package logs

Import Path
	go.pact.im/x/logs (on go.dev)

Dependency Relation
	imports 10 packages, and imported by 0 packages

Involved Source Files Package logs provides [Logger], an alternative [slog] frontend with configurable time source and program counter capture. Logger has no convenience methods. Call [Logger.Log] directly with a level, context, and attributes. Use [Logger.WithTime] to change the time source, and [Logger.WithCapturePC] / [Logger.WithSkipPC] to control PC capture. handler.go logger.go values.go writer.go
Package-Level Type Names (total 9, in which 7 are exported)
/* sort exporteds by: | */
ExpiredContextFilter drops log records once the context expires to reduce noise from [context.Canceled] and similar errors. It suppresses error logs that occur after a request or an operation has already been aborted, e.g. when HTTP client cancels the request. Dropped returns the number of log records that have been dropped due to expired contexts. Note that the counter wraps around on overflow. Enabled returns false if the context has expired, otherwise it delegates to the next handler. Handle drops log record if the context has expired, otherwise it delegates to the next handler. Hooks returns the filter’s hooks.
HandlerFunc is a function that implements the [slog.Handler] interface. Enabled reports whether the handler handles records at the given level. It always returns true. Handle calls f to handle the log record. WithAttrs returns a new handler that merges the given attributes with any attributes from the record when handling. WithGroup returns a new handler that wraps the record’s attributes in a group with the given name. HandlerFunc : log/slog.Handler
Hooks contains hooks for [WrapHandler] that wrap [slog.Handler] methods. Enabled wraps the handler’s Enabled method to determines if a log level is enabled. Handle wraps the handler’s Handle method to intercept records before they reach the next handler. func (*ExpiredContextFilter).Hooks() Hooks func (*LevelLimitFilter).Hooks() Hooks func Wrap(next slog.Handler, hooks Hooks) *WrapHandler
LevelLimitFilter drops log records with a level less than the specified [slog.Leveler]. Level slog.Leveler Enabled returns false if the log level is below the limit, otherwise it delegates to the next handler. Handle drops log record if the log level is below the limit, otherwise it delegates to the next handler. Hooks returns the filter’s hooks.
Logger is an alternative implementation of [slog.Logger] that allows configuring time source and program counter for log records. Unlike [slog.Logger], Logger does not provide convenience methods like Info, Debug, Warn, or Error. Instead, all logging is done through the Log method with explicit context, level, and attributes. Enabled reports whether l emits log records at the given context and level. Handler returns the underlying [slog.Handler]. Log emits a log record with the given level, message, and attributes. By default, [slog.Record.PC] will be set to the caller’s program counter and [slog.Record.Time] will be set to the current time. Use WithCapturePC, WithSkipPC and WithTime methods to change this behavior. WithAttrs returns a [Logger] that includes the given attributes in each output operation. WithCapturePC returns a [Logger] with program counter capture toggled. If v is false, [slog.Record.PC] will not be set regardless of WithSkipPC. WithGroup returns a [Logger] that starts a group. The keys of all attributes added to the [Logger] will be qualified by the given name. If name is empty, WithGroup returns the receiver. WithHandler returns a [Logger] that uses the given [slog.Handler]. WithSkipPC returns a [Logger] that skips additional stack frames. If n is non-positive, WithSkipPC returns the receiver. WithTime returns a [Logger] that uses the given time function. If now is nil, [slog.Record.Time] will not be set. Writer returns a new [Writer] that logs each write to l at the given level and using the given context. func New(h slog.Handler) *Logger func (*Logger).WithAttrs(attrs ...slog.Attr) *Logger func (*Logger).WithCapturePC(v bool) *Logger func (*Logger).WithGroup(name string) *Logger func (*Logger).WithHandler(h slog.Handler) *Logger func (*Logger).WithSkipPC(n int) *Logger func (*Logger).WithTime(now func() time.Time) *Logger func NewLogLogger(ctx context.Context, level slog.Leveler, logger *Logger) *log.Logger
WrapHandler is an [slog.Handler] that uses [Hooks] to modify the behavior of an underlying handler. Enabled implements the [slog.Handler] interface. It calls [Hooks.Enabled] if provided, otherwise it uses the underlying handler. Handle implements the [slog.Handler] interface. It calls [Hooks.Handle] if provided, otherwise it uses the underlying handler. WithAttrs implements the [slog.Handler] interface. WithGroup implements the [slog.Handler] interface. *WrapHandler : log/slog.Handler func Wrap(next slog.Handler, hooks Hooks) *WrapHandler
Writer implements [io.Writer] by logging each write as a single log record at the level specified when the [Writer] was created. Write logs buf as a single record. It returns len(buf), nil if the configured log level is not enabled. *Writer : internal/bisect.Writer *Writer : io.Writer func (*Logger).Writer(ctx context.Context, level slog.Leveler) *Writer
Package-Level Functions (total 10, in which 8 are exported)
Error returns an [slog.Attr] with key "error" for the given error. The value is a group with "type" (the error’s type string from reflection) and "value" (the error itself).
Limit returns a new [slog.Handler] that wraps the provided handler h and only allows records with a level greater than or equal to l.
NamedError returns an [slog.Attr] with the given key for the error. The value is a group with "type" (the error’s type string from reflection) and "value" (the error itself).
New creates a new [Logger] with the given non-nil [slog.Handler].
NewLogLogger returns a [log.Logger] that writes to logger at the given level and context. It assumes a fixed call depth of 2, so it works only when Output is called from [log.Logger]’s log methods like Print or Println.
SliceGroup returns an [slog.Attr] that logs values as a group with numeric keys "0", "1", and so on.
SliceGroupValue returns an [slog.Value] that logs values as a group with numeric keys "0", "1", and so on.
Wrap creates an [slog.Handler] that wraps a handler with specific hooks.