Documentation
¶
Index ¶
- Constants
- func AttrsFromMap(m map[string]any) []any
- func LevelFromEnvironment(name string, fallback slog.Level) (slog.Level, error)
- 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
- type TextMasker
- type UrlMasker
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 ¶
func LevelFromEnvironment ¶ added in v1.113.0
LevelFromEnvironment is the log level the environment variable name holds, read as slog reads a level -- DEBUG, INFO, WARN or ERROR, in any case, with an offset such as INFO+2 -- and fallback where the variable is unset or empty. A value slog cannot read is an error rather than a level guessed at: a service told to log at a level it does not know is misconfigured, and is better stopped at start than left logging at one nobody chose.
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
type TextMasker ¶ added in v1.112.0
TextMasker is a context extractor that can also mask what a line of text says, which the error context extractor asks of each of its extractors that is one: an error's message and the values it carries are written out as text, and are masked as the extractor masks what it writes itself. The HTTP context extractor is one, masking the URLs a text is written with.
type UrlMasker ¶ added in v1.112.0
UrlMasker is a context extractor that can mask a URL known to be one, which finding it in a text cannot always do: a URL that failed to parse, which a *url.Error carries, may hold a space that ends what a text matcher takes for it. The HTTP context extractor is one.
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. |