Documentation
¶
Index ¶
- Constants
- func Debug(msg string, args ...any)
- func DebugCtx(ctx context.Context, msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorCtx(ctx context.Context, msg string, args ...any)
- func HTTPHandler(handler http.Handler) http.Handler
- func Info(msg string, args ...any)
- func InfoCtx(ctx context.Context, msg string, args ...any)
- func MetadataHandler(handler slog.Handler, cfg Config) *metadataHandler
- func TextHandler(out io.Writer, multiline bool) *textHandler
- func Trace(msg string, args ...any)
- func TraceCtx(ctx context.Context, msg string, args ...any)
- func Warn(msg string, args ...any)
- func WarnCtx(ctx context.Context, msg string, args ...any)
- type Attr
- func Any(key string, value any) Attr
- func Bool(key string, v bool) Attr
- func Duration(key string, v time.Duration) Attr
- func Err(v error) Attr
- func Float[T constraints.Float](key string, v T) Attr
- func Group(key string, v ...Attr) Attr
- func Int[T constraints.Signed](key string, v T) Attr
- func JSON(v any) Attr
- func NamedJSON(k string, v any) Attr
- func String(key, value string) Attr
- func Time(key string, v time.Time) Attr
- func Uint[T constraints.Unsigned](key string, v T) Attr
- 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) 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)
Constants ¶
View Source
const CorrelationIDHeaderKey = "X-Correlation-ID"
CorrelationIDHeaderKey is the HTTP header key used for transmitting correlation IDs.
Variables ¶
This section is empty.
Functions ¶
func HTTPHandler ¶
HTTPHandler is a logging middleware for http server ordering multiple middlewares for http.Mux is important logger should be the last one due to Handler call order
Example:
mux := http.NewServeMux() mux.HandleFunc("/v1/hello", HelloHandler) 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 Attr ¶
An Attr is a key-value pair.
type ContextMeta ¶
type ContextMeta string
const ( // CorrelationIdKey is a default key name for go contexts CorrelationIdKey ContextMeta = "correlation_id" // PC - program counter, where log is created PC ContextMeta = "program_counter" )
type Logger ¶
Logger is a custom slog.Logger implementation
var DefaultLogger Logger = NewWithConfiguration(Config{
pcOffset: 1,
})
func NewWithConfiguration ¶
NewWithConfiguration returns logger with given configuration
Source Files
¶
Click to show internal directories.
Click to hide internal directories.