Documentation ¶
Index ¶
- Constants
- func Any(key string, value any) slog.Attr
- func Bool(key string, v bool) slog.Attr
- func Debug(msg string, args ...any)
- func DebugCtx(ctx context.Context, msg string, args ...any)
- func Duration(key string, v time.Duration) slog.Attr
- func Error(msg string, args ...any)
- func ErrorCtx(ctx context.Context, msg string, args ...any)
- func Fatal(msg string, args ...any)
- func FatalCtx(ctx context.Context, msg string, args ...any)
- func Float64(key string, v float64) slog.Attr
- func Group(key string, v ...slog.Attr) slog.Attr
- func HTTPHandler(handler http.Handler) http.Handler
- func Info(msg string, args ...any)
- func InfoCtx(ctx context.Context, msg string, args ...any)
- func Int(key string, value int) slog.Attr
- func Int64(key string, value int64) slog.Attr
- func MetadataHandler(handler slog.Handler, cfg Config) *metadataHandler
- func String(key, value string) slog.Attr
- func TextHandler(out io.Writer, cfg Config) *textHandler
- func Time(key string, v time.Time) slog.Attr
- func Trace(msg string, args ...any)
- func TraceCtx(ctx context.Context, msg string, args ...any)
- func Uint64(key string, v uint64) slog.Attr
- func Warn(msg string, args ...any)
- func WarnCtx(ctx context.Context, msg string, args ...any)
- type Config
- type ContextMeta
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Fatal(msg string, args ...any)
- func (l *Logger) FatalCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Trace(msg string, args ...any)
- func (l *Logger) TraceCtx(ctx context.Context, msg string, args ...any)
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnCtx(ctx context.Context, msg string, args ...any)
- type Metadata
Constants ¶
View Source
const ( LevelTrace = slog.Level(-8) LevelFatal = slog.Level(12) )
Those are missing levels from slog.Logger
View Source
const CorrelationIDHeaderKey = "X-Correlation-ID"
Variables ¶
This section is empty.
Functions ¶
func Any ¶
Any returns any slog.Attr
Use only if value is of a custom type or if specific Attr does not exist
func HTTPHandler ¶
HTTPHandler is a logging middleware for http server
Example:
mux := http.NewServeMux() mux.HandleFunc("/v1/hello", HelloHandler) log.Fatal(http.ListenAndServe(addr, log.HTTPHandler(mux)))
func MetadataHandler ¶
MetadataHandler returns slog.Handler with metadata
func TextHandler ¶
TextHandler returns slog.Handler for rendering message in text format
Types ¶
type ContextMeta ¶
type ContextMeta string
ContextMeta is a type to be used with go context ie. log.CorrelationIdKey is ContextMeta type
context.WithValue(ctx, log.CorrelationIdKey, correlationID)
const CorrelationIDKey ContextMeta = "correlation_id"
CorrelationIDKey is a default key name for go contexts
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a custom slog.Logger implementation
func NewWithConfiguration ¶
NewWithConfiguration returns logger with given configuration
Click to show internal directories.
Click to hide internal directories.