Log is a simple go logging package that is a wrapper aroung slog.
go get github.com/RevittCo/logYou can create your own handler for use with this package. Just make it implement this interface.
type Handler interface {
Enabled(ctx context.Context, l slog.Level) bool
Handle(ctx context.Context, r slog.Record) error
WithAttrs(attrs []slog.Attr) slog.Handler
WithGroup(name string) slog.Handler
}log.SetDefault(log.NewLogger(log.NewTerminalHandler(os.Stdout, log.LevelInfo)))
log.Info("logger initialised")TerminalHandler writes one record per line:
LEVEL [2006-01-02 15:04:05] pkg/file.go:42 message key=value key2="value with spaces"
Attribute values follow logfmt quoting. A value stays bare while it holds no
separator; anything containing a space, ", =, a control character or
invalid UTF-8 is written with strconv.Quote. That is what lets a value be
read back exactly as it was passed in, and it is what stops an embedded
newline from ending the record and forging the next one. EncodeKey,
EncodeValue, EncodeMessage and EncodeAttrValue are exported so a handler
defined elsewhere can emit the same format rather than reimplement the rule.
ANSI colour is written only when the writer is an interactive terminal, and
never when NO_COLOR is set, so logs captured to a file, a pipe or a
container's stdout stay plain text.