logging

package
v0.0.0-...-42eff26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const (
	DeadlineKey = "deadline"
	DurationKey = "duration"
	MethodKey   = "method"
	PathKey     = "path"
	ResponseKey = "jsonPayload"
	StatusKey   = "status"
)

Extended logger attribute keys.

Variables

View Source
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 SetDefault

func SetDefault(l *LeveledLogger)

SetDefault sets the default leveled logger.

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

type AttrHandler func(context.Context) slog.Value

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

type FilterFunc func(context.Context, string, error) bool

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

func (h *GoogleCloudHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.

func (*GoogleCloudHandler) Handle

func (h *GoogleCloudHandler) Handle(ctx context.Context, r slog.Record) error

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 Default

func Default() *LeveledLogger

Default returns the default leveled logger.

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.

func (*LeveledLogger) Trace

func (l *LeveledLogger) Trace(ctx context.Context, msg string, attrs ...any)

Trace logs a message at the trace level.

func (*LeveledLogger) Warning

func (l *LeveledLogger) Warning(ctx context.Context, msg string, attrs ...any)

Warning logs a message at the warning 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

func WithHandler(h slog.Handler) Option

WithHandler returns a logging option to customise the handler used to output log entries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL