Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶ added in v0.0.2
type Handler struct {
// contains filtered or unexported fields
}
Handler is an slog.Handler implementation that uses zerolog to process slog.Record.
func NewConsoleHandler ¶ added in v0.0.2
func NewConsoleHandler(out io.Writer, opts *HandlerOptions) *Handler
NewConsoleHandler creates a new zerolog handler, wrapping out into a zerolog.ConsoleWriter. It's a shortcut to calling
NewHandler(zerolog.New(&zerolog.ConsoleWriter{Out: out, TimeFormat: time.DateTime}).Level(zerolog.InfoLevel), opts)
func NewHandler ¶ added in v0.0.2
func NewHandler(logger zerolog.Logger, opts *HandlerOptions) *Handler
NewHandler creates a *ZerologHandler implementing slog.Handler. It wraps a zerolog.Logger to which log records will be sent.
Unlesse opts.Level is not nil, the logger level is used to filter out records, otherwise opts.Level is used.
The provided logger instance must be configured to not send timestamps or caller information.
If opts is nil, it assumes default options values.
func NewJsonHandler ¶ added in v0.0.2
func NewJsonHandler(out io.Writer, opts *HandlerOptions) *Handler
NewJsonHandler is a shortcut to calling
NewHandler(zerolog.New(out).Level(zerolog.InfoLevel), opts)
type HandlerOptions ¶
type HandlerOptions struct { // AddSource causes the handler to compute the source code position // of the log statement and add a SourceKey attribute to the output. AddSource bool // Level reports the minimum record level that will be logged. // The handler discards records with lower levels. // If Level is nil, the handler assumes the level set in the logger. // The handler calls Level.Level if it's not nil for each record processed; // to adjust the minimum level dynamically, use a LevelVar. Level slog.Leveler }
HandlerOptions are options for a ZerologHandler. A zero HandlerOptions consists entirely of default values.