Documentation ¶
Overview ¶
Package slogext provides slog helpers.
Index ¶
- func NewAtomicBool(t bool) *atomic.Bool
- type GoID
- type HandlerOptions
- type JSONHandler
- type PrefixHandler
- func (h *PrefixHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *PrefixHandler) Handle(ctx context.Context, rec slog.Record) error
- func (h *PrefixHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *PrefixHandler) WithGroup(name string) slog.Handler
- func (h *PrefixHandler) Write(b []byte) (int, error)
- type PrefixHandlerGroup
- type PrivateRedact
- type Request
- type RequestRedactPrivate
- type Stringer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAtomicBool ¶
NewAtomicBool is a convenience function to returns an atomic.Bool with a specified state.
Types ¶
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. // A nil AddSource is false. AddSource *atomic.Bool // Level reports the minimum record level that will be logged. Level slog.Leveler // ReplaceAttr is called to rewrite each non-group attribute before // it is logged. ReplaceAttr func(groups []string, a slog.Attr) slog.Attr }
HandlerOptions are options for a JSONHandler. It is derived from the slog.HandlerOptions with a changed AddSource field type to allow dynamically changing AddSource behaviour during run time. A zero HandlerOptions consists entirely of default values.
type JSONHandler ¶
type JSONHandler struct {
// contains filtered or unexported fields
}
JSONHandler is a slog.Handler that writes Records to an io.Writer as line-delimited JSON objects. It differs from the standard library JSONHandler by allowing alteration of the AddSource behaviour after construction.
func NewJSONHandler ¶
func NewJSONHandler(w io.Writer, opts *HandlerOptions) *JSONHandler
NewJSONHandler creates a JSONHandler that writes to w, using the given options. If opts is nil, the default options are used.
func (*JSONHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*JSONHandler) Handle ¶
Handle formats its argument Record as a JSON object on a single line.
See slog.JSONHandler.Handle for details.
type PrefixHandler ¶
type PrefixHandler struct {
// contains filtered or unexported fields
}
Prefix is a slog.Handler that logs messages with a prefix.
func (*PrefixHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*PrefixHandler) Handle ¶
Handle formats its according to the group's handler, but prefixed with the prefix used to initialise h.
See slog.JSONHandler.Handle for details.
func (*PrefixHandler) WithAttrs ¶
func (h *PrefixHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a new JSONHandler whose attributes consists of h's attributes followed by attrs.
type PrefixHandlerGroup ¶
type PrefixHandlerGroup struct {
// contains filtered or unexported fields
}
PrefixHandlerGroup is a coordinated set of slog.Handlers sharing a single io.Writer.
func NewPrefixHandlerGroup ¶
func NewPrefixHandlerGroup(w io.Writer, h slog.Handler) *PrefixHandlerGroup
NewPrefixHandlerGroup returns a handler group sharing w and h. w must be the io.Writer used to initialise h.
func (*PrefixHandlerGroup) NewHandler ¶
func (g *PrefixHandlerGroup) NewHandler(prefix string) *PrefixHandler
NewHandler returns a PrefixHandler within g's group. Log messages written to the handler will be prefixed with the provided string.
type PrivateRedact ¶
func (PrivateRedact) LogValue ¶
func (v PrivateRedact) LogValue() slog.Value
type Request ¶
Request implements slog.LogValuer for jsonrpc2.Request.
type RequestRedactPrivate ¶
RequestRedactPrivate implements slog.LogValuer for jsonrpc2.Request, redacting fields using private.Redact.
func (RequestRedactPrivate) LogValue ¶
func (v RequestRedactPrivate) LogValue() slog.Value