Documentation
¶
Index ¶
- Constants
- func AttrsFromMap(m map[string]any) []any
- type ContextExtractor
- type ContextExtractorFunction
- type ContextHandler
- func (contextHandler *ContextHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (contextHandler *ContextHandler) Handle(ctx context.Context, record slog.Record) error
- func (contextHandler *ContextHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (contextHandler *ContextHandler) WithGroup(name string) slog.Handler
- type ErrorContextExtractor
- type PartialExtractionError
Constants ¶
const ExtractorErrorKey = "log.extractor_error"
ExtractorErrorKey is where a record says that an extractor failed on it: among the log's own fields, as the size guard's truncation marker is, rather than under error, which is the error the record is about. A single key, not a group, so that it cannot meet another group of that name in one entry.
Variables ¶
This section is empty.
Functions ¶
func AttrsFromMap ¶
Types ¶
type ContextExtractor ¶
type ContextHandler ¶
type ContextHandler struct {
Next slog.Handler
Extractors []ContextExtractor
}
func (*ContextHandler) Handle ¶
Handle runs the extractors before passing the record on. One that fails costs the record what that extractor would have added, never the record itself: what it did add is taken back, unless it vouches for that by returning a PartialExtractionError itself, and the failure is recorded under ExtractorErrorKey. The message is not taken back: an extractor may have masked it, and taking that back would put back what was masked.
func (*ContextHandler) WithAttrs ¶
func (contextHandler *ContextHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a handler of its own, as slog requires: changing this one would hand the attributes to every logger that shares it, and to every record logged after, while those loggers read it from other goroutines.
type ErrorContextExtractor ¶
type ErrorContextExtractor struct {
SkipCause bool
SkipInput bool
SkipStackTrace bool
SkipOutput bool
ContextExtractors []ContextExtractor
}
func (*ErrorContextExtractor) MakeErrorAttrs ¶
func (extractor *ErrorContextExtractor) MakeErrorAttrs(err error) []any
type PartialExtractionError ¶ added in v1.83.0
type PartialExtractionError struct {
Err error
}
PartialExtractionError is an extractor's failure to add some of what it would have, reported with what it did add vouched for: the handler keeps the extractor's fields and records the failure, where it otherwise takes them back.
func (*PartialExtractionError) Error ¶ added in v1.83.0
func (e *PartialExtractionError) Error() string
func (*PartialExtractionError) Unwrap ¶ added in v1.83.0
func (e *PartialExtractionError) Unwrap() error
Directories
¶
| Path | Synopsis |
|---|---|
|
journal_handler
Package journal_handler adapts slog to the systemd journal, recording each record as one journal entry whose priority follows the record's level.
|
Package journal_handler adapts slog to the systemd journal, recording each record as one journal entry whose priority follows the record's level. |
|
Package http_logger makes the logger an HTTP service logs through: JSON entries carrying what is known about the request being logged, which the service's own logging calls need say nothing about.
|
Package http_logger makes the logger an HTTP service logs through: JSON entries carrying what is known about the request being logged, which the service's own logging calls need say nothing about. |
|
Package journal writes entries to the local systemd journal over its native protocol.
|
Package journal writes entries to the local systemd journal over its native protocol. |
|
Package pii_hasher names a person in a log without writing their personal data there: by a keyed hash of it, which is the same for the same value wherever the key is the same -- so that entries, and services sharing the key, can be matched on it, and an address someone gives can be looked up by hashing it -- and which no one without the key can reverse, or test a guessed value against.
|
Package pii_hasher names a person in a log without writing their personal data there: by a keyed hash of it, which is the same for the same value wherever the key is the same -- so that entries, and services sharing the key, can be matched on it, and an address someone gives can be looked up by hashing it -- and which no one without the key can reverse, or test a guessed value against. |