sxcli.dev/fw/sink/file
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:
import _ "sxcli.dev/fw/sink/file"
// then: mybox applet --enable logfile --logfile-path /var/log/box.logThere 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
- type File
- func (s *File) Configured() error
- func (s *File) Enabled(ctx context.Context, level slog.Level) bool
- func (s *File) Handle(ctx context.Context, record slog.Record) error
- func (s *File) Start() error
- func (s *File) Stop() error
- func (s *File) WithAttrs(attrs []slog.Attr) slog.Handler
- func (s *File) WithGroup(name string) slog.Handler
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.
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.
type File struct { // contains filtered or unexported fields }
func (*File) Configured#
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#
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#
func (s *File) Handle(ctx context.Context, record slog.Record) error
Handle delegates to the inner handler.
func (*File) Start#
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#
func (s *File) Stop() error
Stop closes the file.
func (*File) WithAttrs#
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#
func (s *File) WithGroup(name string) slog.Handler
WithGroup returns a derived view sharing the underlying file.