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

sxcli.dev/fw/sink/file

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

Package file provides the log-file sink: a slog.Handler service writing text or json records to an append-only file. It is an ordinary service — cold until an applet requires it or the operator enables it (core `enable`) — never always-on:

code
text
import _ "sxcli.dev/fw/sink/file"
// then: mybox applet --enable logfile --logfile-path /var/log/box.log

There is no rotation: the file is opened O_APPEND and external rotation (logrotate copytruncate) works as-is. Reopen-on-reload may come with ConfigurationUpdated.

Index#

type Config#

Config is the file sink configuration, section "logfile". Path has no default: an enabled file sink without an explicit path is a startup error — guessing one would be worse.

go
go
type Config struct {
    Path   string `json:"path" arg:"logfile-path" usage:"log file path (required when the sink is enabled)"`
    Level  string `json:"level" arg:"logfile-level" usage:"minimum level logged to the file (debug, info, warn, error)"`
    Format string `json:"format" arg:"logfile-format" usage:"file log format: text or json"`
    Mode   string `json:"mode" arg:"logfile-mode" usage:"octal permissions for a newly created log file"`
}

type File#

File is the sink service. Per the sink contract it is fully operational when Configured returns: validation happens first and the open is Configured's last act, so a bad config never creates a file. Stop closes it.

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

func (*File) Configured#

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

Configured validates the configuration and — as its last act — opens the file and builds the inner handler, so the sink is operational for the buffer replay at the multihandler swap.

func (*File) Enabled#

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

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

func (*File) Handle#

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

Handle delegates to the inner handler.

func (*File) Start#

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

Start is a no-op: the file was opened in Configured so the sink could capture the startup replay. The sink stays a Starter because only started Starters receive Stop.

func (*File) Stop#

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

Stop closes the file.

func (*File) WithAttrs#

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

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

func (*File) WithGroup#

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

WithGroup returns a derived view sharing the underlying file.