Documentation
¶
Overview ¶
Package logging provides logging helpers.
Index ¶
- Constants
- func Error(err error) slog.Attr
- func LazyDecoder(raw wirebson.RawDocument) slog.LogValuer
- func LazyDeepDecoder(raw wirebson.RawDocument) slog.LogValuer
- func Logger(out io.Writer, opts *NewHandlerOpts, uuid string) *slog.Logger
- func NewPgxLogger(l *slog.Logger) tracelog.Logger
- func SetupDefault(opts *NewHandlerOpts, uuid string)
- func WithName(l *slog.Logger, name string) *slog.Logger
- type Handler
- func (h *Handler) Enabled(ctx context.Context, l slog.Level) bool
- func (h *Handler) Handle(ctx context.Context, r slog.Record) error
- func (h *Handler) RecentEntries() (*wirebson.Array, error)
- func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *Handler) WithGroup(name string) slog.Handler
- type LazyString
- type MongoLogRecord
- type NewHandlerOpts
Constants ¶
const ( // LevelDPanic panics in development builds. LevelDPanic = slog.LevelError + 1 // LevelPanic always panics. LevelPanic = slog.LevelError + 2 // LevelFatal exits with a non-zero status. LevelFatal = slog.LevelError + 3 )
Variables ¶
This section is empty.
Functions ¶
func Error ¶
Error returns slog.Attr for the given error (that can be nil) with error's message as a value.
func LazyDecoder ¶
func LazyDecoder(raw wirebson.RawDocument) slog.LogValuer
LazyDecoder is a lazily evaluated slog.LogValuer for wirebson.RawDocument that tries to decode the document.
func LazyDeepDecoder ¶
func LazyDeepDecoder(raw wirebson.RawDocument) slog.LogValuer
LazyDeepDecoder is a lazily evaluated slog.LogValuer for wirebson.RawDocument that tries to deeply decode the document.
func NewPgxLogger ¶
NewPgxLogger creates a new tracelog.Logger that uses given slog.Logger.
func SetupDefault ¶
func SetupDefault(opts *NewHandlerOpts, uuid string)
SetupDefault initializes global slog logging with given options and UUID.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog.Handler that wraps another handler with support for:
- additional log levels (DPanic/ERROR+1 panics in development builds, Panic/ERROR+2 always panics, Fatal/ERROR+3 exits with a non-zero status);
- shorter source locations;
- removal of time, level, and source attributes;
- message checks for leading/trailing spaces and ending punctuation;
- collecting recent log entries for `getLog` command.
func NewHandler ¶
func NewHandler(out io.Writer, opts *NewHandlerOpts) *Handler
NewHandler creates a new handler with the given options.
func (*Handler) Enabled ¶
Enabled implements slog.Handler.
func (*Handler) Handle ¶
Handle implements slog.Handler.
func (*Handler) RecentEntries ¶
RecentEntries returns recent log entries.
func (*Handler) WithAttrs ¶
WithAttrs implements slog.Handler.
type LazyString ¶
type LazyString func() string
LazyString is a lazily evaluated slog.LogValuer for string.
func (LazyString) LogValue ¶
func (ls LazyString) LogValue() slog.Value
LogValue implements slog.LogValuer.
type MongoLogRecord ¶
type MongoLogRecord struct {
Timestamp time.Time `bson:"t"`
Severity string `bson:"s"`
Component string `bson:"c"` // TODO https://github.com/hanzoai/docdb/issues/4431
ID int `bson:"id,omitempty"`
Ctx string `bson:"ctx"`
Msg string `bson:"msg"`
Attr map[string]any `bson:"attr,omitempty"`
Tags []string `bson:"tags,omitempty"`
}
MongoLogRecord represents a single log message in mongo structured JSON format. For now it lacks the fields that are not used by any caller.
func (*MongoLogRecord) Marshal ¶
func (log *MongoLogRecord) Marshal() ([]byte, error)
Marshal returns the mongo structured JSON encoding of log.
type NewHandlerOpts ¶
type NewHandlerOpts struct {
Base string // base handler to create: "console", "text", "json" or "mongo"
Level slog.Leveler
RemoveTime bool
RemoveLevel bool
RemoveSource bool
// When unset, causes handler to panic on messages with leading/trailing spaces or ending punctuation.
// We can't enable checks everywhere because we don't control messages from third-party packages.
// But we should check our own messages.
SkipChecks bool
// contains filtered or unexported fields
}
NewHandlerOpts represents NewHandler options.