Documentation
¶
Index ¶
- Constants
- Variables
- func NewContext(parent context.Context, logger *LeveledLogger) context.Context
- func RequestLogger(opts ...Option) transport.Middleware
- func SetDefault(l *LeveledLogger)
- func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor
- func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor
- type AttrHandler
- type CloudWatchHandler
- type FilterFunc
- type GoogleCloudHandler
- func (h *GoogleCloudHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *GoogleCloudHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *GoogleCloudHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *GoogleCloudHandler) WithGroup(name string) slog.Handler
- func (h *GoogleCloudHandler) WithLabels(labels map[string]string) slog.Handler
- type LeveledLogger
- func (l *LeveledLogger) Alert(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Critical(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Debug(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Emergency(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Error(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Info(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Notice(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Trace(ctx context.Context, msg string, attrs ...any)
- func (l *LeveledLogger) Warning(ctx context.Context, msg string, attrs ...any)
- type Option
Constants ¶
const ( LevelTrace = slog.Level(-8) LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelNotice = slog.Level(2) LevelWarning = slog.LevelWarn LevelError = slog.LevelError LevelEmergency = slog.Level(12) LevelAlert = slog.Level(16) LevelCritical = slog.Level(20) )
Level denotes the severity of a log entry.
const ( DeadlineKey = "deadline" DurationKey = "duration" MethodKey = "method" PathKey = "path" ResponseKey = "jsonPayload" StatusKey = "status" )
Extended logger attribute keys.
Variables ¶
var NilValue = slog.AnyValue(nil)
NilValue is a slog.Value that represents a nil value.
Functions ¶
func NewContext ¶
func NewContext(parent context.Context, logger *LeveledLogger) context.Context
NewContext returns a new Context that carries a LeveledLogger.
func RequestLogger ¶
func RequestLogger(opts ...Option) transport.Middleware
RequestLogger returns a middleware that instantiates a request scoped logger and injects it into the request context to be used within subsequent middlewares and handlers.
func StreamServerInterceptor ¶
func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor
StreamServerInterceptor is a server side stream interceptor logging the payloads for a single stream. Unlike the unary interceptor the payload of each message in the stream will be collected and logged together.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor
UnaryServerInterceptor is a server side unary interceptor logging the payloads for a single request/response.
Types ¶
type AttrHandler ¶
AttrHandler is a function that can be used to add additional attributes to a log entry.
type CloudWatchHandler ¶
type CloudWatchHandler struct {
*slog.JSONHandler
}
CloudWatchHandler is a handler that formats log messages in a way that is compatible with AWS CloudWatch.
func NewCloudWatchHandler ¶
func NewCloudWatchHandler(w io.Writer, level slog.Level) *CloudWatchHandler
NewCloudWatchHandler returns a new CloudWatchHandler.
type FilterFunc ¶
FilterFunc customises the behaviour used to determine log suppression.
type GoogleCloudHandler ¶
type GoogleCloudHandler struct { SpanHandler AttrHandler TraceHandler AttrHandler // contains filtered or unexported fields }
GoogleCloudHandler is a handler that formats log messages in a way that is compatible with Google Cloud Logging.
func NewGoogleCloudHandler ¶
func NewGoogleCloudHandler(w io.Writer, level slog.Level) *GoogleCloudHandler
NewGoogleCloudHandler returns a new
func (*GoogleCloudHandler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*GoogleCloudHandler) Handle ¶
Handle formats its argument Record as a JSON object on a single line.
func (*GoogleCloudHandler) WithAttrs ¶
func (h *GoogleCloudHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a new GoogleCloudHandler whose attributes consists of h's attributes followed by attrs.
func (*GoogleCloudHandler) WithGroup ¶
func (h *GoogleCloudHandler) WithGroup(name string) slog.Handler
WithGroup returns a new GoogleCloudHandler whose attributes consists of h's attributes followed by a group with the given name.
func (*GoogleCloudHandler) WithLabels ¶
func (h *GoogleCloudHandler) WithLabels(labels map[string]string) slog.Handler
WithLabels returns a new GoogleCloudHandler whose attributes consists of h's attributes followed by the given labels.
type LeveledLogger ¶
type LeveledLogger struct {
// contains filtered or unexported fields
}
LeveledLogger is a logger that logs messages at a specific level.
func FromContext ¶
func FromContext(ctx context.Context) *LeveledLogger
FromContext returns the LeveledLogger value stored in ctx, if any. If no LeveledLogger can be found then a default logger is returned.
func New ¶
func New(h slog.Handler) *LeveledLogger
New returns a new leveled logger that logs messages to the given handler.
func (*LeveledLogger) Alert ¶
func (l *LeveledLogger) Alert(ctx context.Context, msg string, attrs ...any)
Alert logs a message at the alert level.
func (*LeveledLogger) Critical ¶
func (l *LeveledLogger) Critical(ctx context.Context, msg string, attrs ...any)
Critical logs a message at the critical level.
func (*LeveledLogger) Debug ¶
func (l *LeveledLogger) Debug(ctx context.Context, msg string, attrs ...any)
Debug logs a message at the debug level.
func (*LeveledLogger) Emergency ¶
func (l *LeveledLogger) Emergency(ctx context.Context, msg string, attrs ...any)
Emergency logs a message at the emergency level.
func (*LeveledLogger) Error ¶
func (l *LeveledLogger) Error(ctx context.Context, msg string, attrs ...any)
Error logs a message at the error level.
func (*LeveledLogger) Info ¶
func (l *LeveledLogger) Info(ctx context.Context, msg string, attrs ...any)
Info logs a message at the info level.
func (*LeveledLogger) Notice ¶
func (l *LeveledLogger) Notice(ctx context.Context, msg string, attrs ...any)
Notice logs a message at the notice level.
type Option ¶
type Option func(*options)
Option is a function that can configure one or more logging options.
func WithFilter ¶
func WithFilter(f FilterFunc) Option
WithFilter returns a logging option to suppress log entries based on the provided filter function.
func WithHandler ¶
WithHandler returns a logging option to customise the handler used to output log entries.