Documentation
¶
Index ¶
- Constants
- Variables
- func Destructure(err error) (attrs []slog.Attr)
- func Err(err error) slog.Attr
- func ErrColor(value slog.Attr) slog.Attr
- func FromContext(ctx context.Context) *slog.Logger
- func InstallGoLogShim()
- func JSON(key string, j json.RawMessage) slog.Attr
- func LevelAttrReplacer(_ []string, a slog.Attr) slog.Attr
- func MustNewHandler(format Format, level slog.Level) slog.Handler
- func NewError(err error, msg string, attrs ...slog.Attr) error
- func NewHandler(format Format, level slog.Level) (slog.Handler, error)
- func NewHandlerTo(w io.Writer, format Format, level slog.Level) (slog.Handler, error)
- func Severity(err error, level slog.Level) error
- func Stack(skip int) slog.Attr
- func User(user UserValue) slog.Attr
- func WithLogContext(ctx context.Context, log *slog.Logger) context.Context
- type Config
- type Format
- type Level
- type LogWriterShim
- type Scope
- type UserValue
Constants ¶
const ( LevelTrace slog.Level = -8 LevelFatal slog.Level = 12 )
const ErrKey = "error"
const StackKey = "stack"
const UserKey = "usr"
Variables ¶
var DefaultConfig = Config{ Level: Level(slog.LevelInfo), Format: FormatText, }
var LevelNames = map[slog.Level]string{ LevelTrace: "TRACE", LevelFatal: "FATAL", }
var NameLevels = func() map[string]slog.Level { m := make(map[string]slog.Level, len(LevelNames)) for l, n := range LevelNames { m[n] = l } if len(LevelNames) != len(m) { panic("duplicate level value or name") } return m }()
Functions ¶
func Destructure ¶
Destructure recursively extracts attributes from an error chain with scopedError entries. The error chain is modified! Only the first chain with a scopedError is processed for error trees created via errors.Join.
func InstallGoLogShim ¶
func InstallGoLogShim()
func MustNewHandler ¶
MustNewHandler forwards to NewHandler and panics when it fails. It is still used by AVAS, can eventually go away for mainutil.
func NewError ¶
NewError attaches additional attributes to an error. It is allowed to pass a nil err to create a new leaf error. Use it in place of fmt.Errorf("message %q: %w", "detail", err) for nicer formatting in logs. Use Scope for grouping error attributes.
func NewHandlerTo ¶
Types ¶
type Config ¶
type Config struct {
Level Level `usage:"TRACE, DEBUG, INFO, WARN, or ERROR"`
Format Format `usage:"TEXT or JSON"`
}
func (Config) InstallForProcess ¶
type Level ¶
func (*Level) UnmarshalText ¶
type LogWriterShim ¶
type LogWriterShim struct {
// contains filtered or unexported fields
}
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope collects attributes for later instantiation of a logger or an error.
func NewScope ¶
NewScope returns a scope with attributes for later instantiation of a logger or an error. The scope's group name is used for grouping the scope's attributes via slog.Group.
func (*Scope) Err ¶
Err wraps an error to propagate the scope's current attributes, plus additional attributes. The inner error should not be nil.
func (*Scope) Log ¶
Log returns a slog.Logger with the scope's current attributes, plus additional attributes.