Documentation ¶
Index ¶
- Variables
- func Configure(opts Options)
- func Handler(logger *slog.Logger) func(next http.Handler) http.Handler
- func LogEntry(ctx context.Context) slog.Logger
- func LogEntrySetField(ctx context.Context, key, value string)
- func LogEntrySetFields(ctx context.Context, fields map[string]interface{})
- func NewLogger(serviceName string, opts ...Options) *slog.Logger
- func RequestLogger(logger *slog.Logger) func(next http.Handler) http.Handler
- type Options
- type PrettyHandler
- type RequestLoggerEntry
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultHandlerConfig = &slog.HandlerOptions{ AddSource: true, Level: slog.LevelInfo, }
View Source
var DefaultOptions = Options{ LogLevel: "info", LevelFieldName: "level", JSON: false, Concise: false, Tags: nil, SkipHeaders: nil, QuietDownRoutes: nil, QuietDownPeriod: 0, TimeFieldFormat: time.RFC3339Nano, TimeFieldName: "timestamp", }
View Source
var IsTTY bool
Functions ¶
func Configure ¶
func Configure(opts Options)
Configure will set new global/default options for the httplog and behaviour of underlying zerolog pkg and its global logger.
func LogEntrySetField ¶
func LogEntrySetFields ¶
Types ¶
type Options ¶
type Options struct { // LogLevel defines the minimum level of severity that app should log. // Must be one of: // "debug", "info", "warn", "error" LogLevel string // LevelFieldName sets the field name for the log level or severity. // Some providers parse and search for different field names. LevelFieldName string // JSON enables structured logging output in json. Make sure to enable this // in production mode so log aggregators can receive data in parsable format. // // In local development mode, its appropriate to set this value to false to // receive pretty output and stacktraces to stdout. JSON bool // Concise mode includes fewer log details during the request flow. For example // excluding details like request content length, user-agent and other details. // This is useful if during development your console is too noisy. Concise bool // Tags are additional fields included at the root level of all logs. // These can be useful for example the commit hash of a build, or an environment // name like prod/stg/dev Tags map[string]string // SkipHeaders are additional headers which are redacted from the logs SkipHeaders []string // QuietDownRoutes are routes which are temporarily excluded from logging for a QuietDownPeriod after it occurs // for the first time // to cancel noise from logging for routes that are known to be noisy. QuietDownRoutes []string // QuietDownPeriod is the duration for which a route is excluded from logging after it occurs for the first time // if the route is in QuietDownRoutes QuietDownPeriod time.Duration // TimeFieldFormat defines the time format of the Time field, defaulting to "time.RFC3339Nano" see options at: // https://pkg.go.dev/time#pkg-constants TimeFieldFormat string // TimeFieldName sets the field name for the time field. // Some providers parse and search for different field names. TimeFieldName string // SourceFieldName sets the field name for the source field which logs // the location where the logger was called // its "" if not enabled SourceFieldName string }
type PrettyHandler ¶
type PrettyHandler struct {
// contains filtered or unexported fields
}
func NewPrettyHandler ¶
func NewPrettyHandler(w io.Writer, op ...*slog.HandlerOptions) *PrettyHandler
type RequestLoggerEntry ¶
func (*RequestLoggerEntry) Panic ¶
func (l *RequestLoggerEntry) Panic(v interface{}, stack []byte)
Click to show internal directories.
Click to hide internal directories.