Documentation
¶
Overview ¶
Package flog wraps *slog.Logger with a zerolog-style fluent API while preserving slog's handler ecosystem.
The underlying transport remains a *slog.Logger, so any slog.Handler — the stdlib JSON/Text handlers, the phuslu and zerolog adapters under integrations/log/, or any third-party Handler — works unchanged. Callers pick the backend by passing the appropriate *slog.Logger via fastconf.WithLogger.
Usage:
log := flog.New(slog.Default())
log.Info().
Str("reason", reason).
Uint64("generation", gen).
Int("layers", n).
Err(err).
Msg("reload swap")
At a disabled level Info()/Debug()/etc. return nil and every fluent method short-circuits on nil, so the chain costs only the level check. Events are pooled, so each emit is amortized zero-allocation aside from the slog.Record path inside the chosen Handler.
Index ¶
- type Context
- func (c *Context) Any(k string, v any) *Context
- func (c *Context) Bool(k string, v bool) *Context
- func (c *Context) Dur(k string, v time.Duration) *Context
- func (c *Context) Group(name string) *Context
- func (c *Context) Int(k string, v int) *Context
- func (c *Context) Int64(k string, v int64) *Context
- func (c *Context) Logger() *Logger
- func (c *Context) Str(k, v string) *Context
- func (c *Context) Time(k string, v time.Time) *Context
- func (c *Context) Uint64(k string, v uint64) *Context
- type Event
- func (e *Event) Any(k string, v any) *Event
- func (e *Event) Attr(a slog.Attr) *Event
- func (e *Event) Bool(k string, v bool) *Event
- func (e *Event) Dur(k string, v time.Duration) *Event
- func (e *Event) Err(err error) *Event
- func (e *Event) Float64(k string, v float64) *Event
- func (e *Event) Int(k string, v int) *Event
- func (e *Event) Int64(k string, v int64) *Event
- func (e *Event) Msg(msg string)
- func (e *Event) NamedErr(k string, err error) *Event
- func (e *Event) Send()
- func (e *Event) Str(k, v string) *Event
- func (e *Event) Strs(k string, v []string) *Event
- func (e *Event) Time(k string, v time.Time) *Event
- func (e *Event) Uint64(k string, v uint64) *Event
- type Logger
- func (l *Logger) At(lvl slog.Level) *Event
- func (l *Logger) AtCtx(ctx context.Context, lvl slog.Level) *Event
- func (l *Logger) Debug() *Event
- func (l *Logger) DebugCtx(ctx context.Context) *Event
- func (l *Logger) Error() *Event
- func (l *Logger) ErrorCtx(ctx context.Context) *Event
- func (l *Logger) Info() *Event
- func (l *Logger) InfoCtx(ctx context.Context) *Event
- func (l *Logger) Slog() *slog.Logger
- func (l *Logger) Warn() *Event
- func (l *Logger) WarnCtx(ctx context.Context) *Event
- func (l *Logger) With() *Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is the builder returned by Logger.With(); call Logger() to materialize a derived *Logger that attaches the accumulated attrs to every record it emits.
func (*Context) Group ¶
Group nests subsequent records under name (slog.Logger.WithGroup semantics).
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event is a level-gated, attribute-accumulating builder. A nil *Event is a no-op — every fluent method tolerates nil so disabled-level chains short-circuit after the initial level check.
func (*Event) Dur ¶
Dur attaches a time.Duration. Stdlib slog renders it as a nanosecond int64 by default; the phuslu and zerolog adapters render it in their native duration form.
func (*Event) Err ¶
Err attaches an error under the conventional key "err". Nil errors are silently skipped so chains can stay flat (.Err(err) instead of an if).
func (*Event) Msg ¶
Msg emits the event with msg and returns the *Event to the pool. After Msg() the receiver must not be reused.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger wraps a *slog.Logger with fluent builder methods. A zero-value Logger is invalid; use New().