Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AttributeKeyInvalidCharReplacement = "_"
View Source
var ErrorKeys = []string{"error", "err"}
View Source
var SourceKey = "source"
View Source
var SubAttributeSeparator = "__"
See:
Functions ¶
func DefaultConverter ¶
func RemoveAttrsConverter ¶ added in v3.6.0
func RemoveAttrsConverter(addSource bool, replaceAttr func(groups []string, a slog.Attr) slog.Attr, loggerAttr []slog.Attr, groups []string, record *slog.Record) model.LabelSet
This converter removes all record attributes, sending only the fixed logger attributes as labels.
Use this converter along with Option.HandleRecordsWithMetadata set to true to send record attributes as structured metadata.
See https://grafana.com/docs/loki/latest/get-started/labels/structured-metadata/ to know more about structured metadata in Loki.
Types ¶
type LokiHandler ¶
type LokiHandler struct {
// contains filtered or unexported fields
}
type Option ¶
type Option struct {
// log level (default: debug)
Level slog.Leveler
// loki
Client *loki.Client
// optional: customize webhook event builder
Converter Converter
// optional: fetch attributes from context
AttrFromContext []func(ctx context.Context) []slog.Attr
// optional: see slog.HandlerOptions
AddSource bool
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
// By default, LokiHandler.Handle sends record attributes as labels to Loki.
// When set to true, this handler sends record attributes as structured metadata.
//
// Combine with RemoveAttrsConverter to avoid sending attributes as labels.
//
// Learn more about structured metadata in Loki:
// https://grafana.com/docs/loki/latest/get-started/labels/structured-metadata/
HandleRecordsWithMetadata bool
}
func (Option) NewLokiHandler ¶
Creating a Loki client at each `NewLokiHandler` call may lead to connection leak when chaining many operations: `logger.With(...).With(...).With(...).With(...)`
Click to show internal directories.
Click to hide internal directories.