Documentation
¶
Overview ¶
Package logger provides a preinitialized slog logger ready for use.
Additionally it provides middlewares for use with http handlers to record access logs.
Index ¶
- Constants
- func AccessLogMiddleware(next http.Handler) http.Handler
- func ContextWithAttr(parent context.Context, attr slog.Attr) context.Context
- func Err(err error) slog.Attr
- func InitLogger(writer io.Writer, filepath string, verbose bool, debug bool) error
- func ParseLevel(levelStr string) slog.Level
- func RequestIDMiddleware(next http.Handler) http.Handler
- func SetLogLevel(level slog.Level) error
- func ValidateLevel(levelStr string) error
Constants ¶
const ( LevelTrace slog.Level = -8 LevelTraceString = "TRACE" )
const MaximumValueLength = 2000
Variables ¶
This section is empty.
Functions ¶
func ContextWithAttr ¶
ContextWithAttr returns a copy of parent in which the attr is added to the list of slog attributes attached to the context.
Use context slog attributes only for request-scoped log attributes.
func Err ¶
Err is a helper function to ensure errors are always logged with the key "err". Additionally this becomes the single point in code, where we could tweak how errors are logged, e.g. to handle application specific error types or to add stack trace information in debug mode.
func InitLogger ¶
func ParseLevel ¶
ParseLevel converts a given string representation for a log level into an actual slog.Level. Defaults to log level warn.
func SetLogLevel ¶
SetLogLevel replaces the default logger with a logger of the given log level.
func ValidateLevel ¶
ValidateLevel checks a given string representation for a log level against the supported log levels.
Types ¶
This section is empty.