sxcli.devSimple Extensible CLI
You are viewing an archived snapshot (v0.1.0). Switch to the current version →

sxcli.dev/fw/sink/console

go
go
import "sxcli.dev/fw/sink/console"

Package console provides the console log sink: a slog.Handler service writing text or json records to stderr (default) or stdout. It registers itself as always-on, so a binary that imports it has sane log output with no further wiring:

code
text
import _ "sxcli.dev/fw/sink/console"

Index#

type Config#

Config is the console sink configuration, section "console".

go
go
type Config struct {
    Level  string `json:"level" arg:"console-level" usage:"minimum level logged to the console (debug, info, warn, error)"`
    Format string `json:"format" arg:"console-format" usage:"console log format: text or json"`
    Output string `json:"output" arg:"console-output" usage:"console log destination: stderr or stdout"`
}

type Console#

Console is the sink service. Until Configured builds the inner handler the sink is inert: disabled, handling nothing.

go
go
type Console struct {
    // contains filtered or unexported fields
}

func (*Console) Configured#

go
go
func (s *Console) Configured() error

Configured builds the inner handler from the merged configuration.

func (*Console) Enabled#

go
go
func (s *Console) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether the record would be logged; an unconfigured sink accepts nothing.

func (*Console) Handle#

go
go
func (s *Console) Handle(ctx context.Context, record slog.Record) error

Handle delegates to the inner handler.

func (*Console) Start#

go
go
func (s *Console) Start() error

Start is a no-op: the console needs no acquisition.

func (*Console) Stop#

go
go
func (s *Console) Stop() error

Stop is a no-op: stderr and stdout are not ours to close.

func (*Console) WithAttrs#

go
go
func (s *Console) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a derived view sharing the underlying output, per the sink-author contract.

func (*Console) WithGroup#

go
go
func (s *Console) WithGroup(name string) slog.Handler

WithGroup returns a derived view sharing the underlying output.