logger

package
v1.1.65 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelNotice    slog.Level = slog.Level(2)
	LevelCritical  slog.Level = slog.Level(10)
	LevelAlert     slog.Level = slog.Level(12)
	LevelEmergency slog.Level = slog.Level(14)
)

Variables

This section is empty.

Functions

func Alert added in v1.1.11

func Alert(msg string, args ...any)

Alert logs at LevelAlert using the default logger.

func AlertContext added in v1.1.11

func AlertContext(ctx context.Context, msg string, args ...any)

AlertContext logs at LevelAlert with the given context using the default logger.

func AppendCtx

func AppendCtx(parent context.Context, attr slog.Attr) context.Context

Appends an attribute to the context for logging. If the attribute key already exists, it replaces the value instead of appending. Context attributes are always added at the top level, regardless of logger groups.

func Critical added in v1.1.11

func Critical(msg string, args ...any)

Critical logs at LevelCritical using the default logger.

func CriticalContext added in v1.1.11

func CriticalContext(ctx context.Context, msg string, args ...any)

CriticalContext logs at LevelCritical with the given context using the default logger.

func Debug added in v1.1.11

func Debug(msg string, args ...any)

Debug logs at LevelDebug using the default logger.

func DebugContext added in v1.1.11

func DebugContext(ctx context.Context, msg string, args ...any)

DebugContext logs at LevelDebug with the given context using the default logger.

func Emergency added in v1.1.11

func Emergency(msg string, args ...any)

Emergency logs at LevelEmergency using the default logger.

func EmergencyContext added in v1.1.11

func EmergencyContext(ctx context.Context, msg string, args ...any)

EmergencyContext logs at LevelEmergency with the given context using the default logger.

func EntMutationAttrs added in v1.1.13

func EntMutationAttrs(m ent.Mutation) []any

EntMutationAttrs constructs log attributes for the given Ent mutation.

func Error added in v1.1.11

func Error(msg string, args ...any)

Error logs at LevelError using the default logger.

func ErrorContext added in v1.1.11

func ErrorContext(ctx context.Context, msg string, args ...any)

ErrorContext logs at LevelError with the given context using the default logger.

func ExtractAttrs added in v1.1.12

func ExtractAttrs(err error) []slog.Attr

ExtractAttrs extracts all log attributes from an error chain

func GetFullRequestAttributes added in v1.1.14

func GetFullRequestAttributes(ctx context.Context, r *http.Request) []any

GetFullRequestAttributes constructs error log attributes for the given error and context.

func Info added in v1.1.11

func Info(msg string, args ...any)

Info logs at LevelInfo using the default logger.

func InfoContext added in v1.1.11

func InfoContext(ctx context.Context, msg string, args ...any)

InfoContext logs at LevelInfo with the given context using the default logger.

func Log added in v1.1.11

func Log(ctx context.Context, level slog.Level, msg string, args ...any)

Log emits a log record with the current time and the given level and message using the default logger.

func LogAttrs added in v1.1.11

func LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)

LogAttrs emits a log record with the current time and the given level and message using the default logger.

func NewGoogleSlogger added in v1.1.11

func NewGoogleSlogger(opts *GoogleHandlerOptions) *slog.Logger

func NewPrettySlogger added in v1.1.11

func NewPrettySlogger(opts *PrettyHandlerOptions) *slog.Logger

func Notice added in v1.1.11

func Notice(msg string, args ...any)

Notice logs at LevelNotice using the default logger.

func NoticeContext added in v1.1.11

func NoticeContext(ctx context.Context, msg string, args ...any)

NoticeContext logs at LevelNotice with the given context using the default logger.

func SetDefault added in v1.1.11

func SetDefault(l *Logger)

SetDefault makes l the default Logger.

func Warn added in v1.1.11

func Warn(msg string, args ...any)

Warn logs at LevelWarn using the default logger.

func WarnContext added in v1.1.11

func WarnContext(ctx context.Context, msg string, args ...any)

WarnContext logs at LevelWarn with the given context using the default logger.

func WrapError added in v1.1.12

func WrapError(err error, attrs ...slog.Attr) error

WrapError wraps an error with log attributes

Types

type ErrorWithAttrs added in v1.1.12

type ErrorWithAttrs struct {
	// contains filtered or unexported fields
}

func (*ErrorWithAttrs) Error added in v1.1.12

func (e *ErrorWithAttrs) Error() string

func (*ErrorWithAttrs) Unwrap added in v1.1.12

func (e *ErrorWithAttrs) Unwrap() error

type GoogleHandler added in v1.1.9

type GoogleHandler struct {
	// contains filtered or unexported fields
}

func NewGoogleHandler added in v1.1.9

func NewGoogleHandler(opts *GoogleHandlerOptions) *GoogleHandler

func (*GoogleHandler) Enabled added in v1.1.9

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

func (*GoogleHandler) Handle added in v1.1.9

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

func (*GoogleHandler) WithAttrs added in v1.1.9

func (h *GoogleHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*GoogleHandler) WithGroup added in v1.1.9

func (h *GoogleHandler) WithGroup(name string) slog.Handler

type GoogleHandlerOptions added in v1.1.9

type GoogleHandlerOptions struct {
	Level slog.Leveler
}

type Logger added in v1.1.11

type Logger struct {
	// contains filtered or unexported fields
}

Logger wraps slog.Logger with additional methods

func Default added in v1.1.11

func Default() *Logger

Default returns the default Logger.

func New added in v1.1.11

func New(s *slog.Logger) *Logger

New creates a Logger with the given handler

func With added in v1.1.15

func With(args ...any) *Logger

With returns a Logger that includes the given attributes in each output operation using the default logger.

func WithError added in v1.1.15

func WithError(err error) *Logger

WithError returns a Logger that includes the given error in each output operation.

func WithRequest added in v1.1.15

func WithRequest(ctx context.Context, r *http.Request) *Logger

WithRequest returns a Logger that includes request attributes in each output operation.

func (*Logger) Alert added in v1.1.11

func (l *Logger) Alert(msg string, args ...any)

Alert logs at LevelAlert.

func (*Logger) AlertContext added in v1.1.11

func (l *Logger) AlertContext(ctx context.Context, msg string, args ...any)

AlertContext logs at LevelAlert with the given context.

func (*Logger) Critical added in v1.1.11

func (l *Logger) Critical(msg string, args ...any)

Critical logs at LevelCritical.

func (*Logger) CriticalContext added in v1.1.11

func (l *Logger) CriticalContext(ctx context.Context, msg string, args ...any)

CriticalContext logs at LevelCritical with the given context.

func (*Logger) Debug added in v1.1.11

func (l *Logger) Debug(msg string, args ...any)

Debug logs at LevelDebug.

func (*Logger) DebugContext added in v1.1.11

func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)

DebugContext logs at LevelDebug with the given context.

func (*Logger) Emergency added in v1.1.11

func (l *Logger) Emergency(msg string, args ...any)

Emergency logs at LevelEmergency.

func (*Logger) EmergencyContext added in v1.1.11

func (l *Logger) EmergencyContext(ctx context.Context, msg string, args ...any)

EmergencyContext logs at LevelEmergency with the given context.

func (*Logger) Enabled added in v1.1.11

func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether the Logger emits log records at the given level.

func (*Logger) Error added in v1.1.11

func (l *Logger) Error(msg string, args ...any)

Error logs at LevelError.

func (*Logger) ErrorContext added in v1.1.11

func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)

ErrorContext logs at LevelError with the given context.

func (*Logger) Handler added in v1.1.11

func (l *Logger) Handler() slog.Handler

Handler returns the Handler associated with the Logger.

func (*Logger) Info added in v1.1.11

func (l *Logger) Info(msg string, args ...any)

Info logs at LevelInfo.

func (*Logger) InfoContext added in v1.1.11

func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)

InfoContext logs at LevelInfo with the given context.

func (*Logger) Log added in v1.1.11

func (l *Logger) Log(ctx context.Context, level slog.Level, msg string, args ...any)

Log emits a log record with the current time and the given level and message.

func (*Logger) LogAttrs added in v1.1.11

func (l *Logger) LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)

LogAttrs emits a log record with the current time and the given level and message.

func (*Logger) Notice added in v1.1.11

func (l *Logger) Notice(msg string, args ...any)

Notice logs at LevelNotice.

func (*Logger) NoticeContext added in v1.1.11

func (l *Logger) NoticeContext(ctx context.Context, msg string, args ...any)

NoticeContext logs at LevelNotice with the given context.

func (*Logger) Slog added in v1.1.11

func (l *Logger) Slog() *slog.Logger

Slog returns the underlying *slog.Logger.

func (*Logger) Warn added in v1.1.11

func (l *Logger) Warn(msg string, args ...any)

Warn logs at LevelWarn.

func (*Logger) WarnContext added in v1.1.11

func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)

WarnContext logs at LevelWarn with the given context.

func (*Logger) With added in v1.1.11

func (l *Logger) With(args ...any) *Logger

With returns a Logger that includes the given attributes in each output operation.

func (*Logger) WithError added in v1.1.15

func (l *Logger) WithError(err error) *Logger

WithError returns a Logger that includes the given error in each output operation.

func (*Logger) WithGroup added in v1.1.11

func (l *Logger) WithGroup(name string) *Logger

WithGroup returns a Logger that starts a group.

func (*Logger) WithRequest added in v1.1.15

func (l *Logger) WithRequest(ctx context.Context, r *http.Request) *Logger

WithRequest returns a Logger that includes request attributes in each output operation.

type PrettyHandler

type PrettyHandler struct {
	// contains filtered or unexported fields
}

func NewPrettyHandler

func NewPrettyHandler(opts *PrettyHandlerOptions) *PrettyHandler

func (*PrettyHandler) Enabled added in v1.1.9

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

func (*PrettyHandler) Handle

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

func (*PrettyHandler) WithAttrs added in v1.1.9

func (h *PrettyHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*PrettyHandler) WithGroup added in v1.1.9

func (h *PrettyHandler) WithGroup(name string) slog.Handler

type PrettyHandlerOptions

type PrettyHandlerOptions struct {
	Level slog.Leveler
}

Jump to

Keyboard shortcuts

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