Documentation
¶
Overview ¶
Package pl tails and pretty-prints JSONL logs produced by zap (the zap.NewProductionConfig JSON encoder used by go-faster/sdk) as well as OpenTelemetry log records in the logs data model JSON form, plus the plain-text logfmt and klog formats. Each line is detected and normalized onto a shared rendering path, so a stream mixing the formats reads uniformly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLevelStyles ¶
func DefaultLevelStyles() map[zapcore.Level]LevelStyle
DefaultLevelStyles returns the built-in level styles: a single-character label and a color per level (D/I/W/E, and C for dpanic/panic/fatal).
Types ¶
type Formatter ¶
type Formatter struct {
// Color enables ANSI colors in the output.
Color bool
// MinLevel, when set, drops lines below this level.
MinLevel zapcore.Level
// TraceID, when set, drops every line whose trace_id does not match,
// isolating a single trace across a stream. The comparison is
// case-insensitive and matches whether the id came from a zap trace_id
// field, zctx's reflected ctx object, or an OTEL TraceID. Lines that carry
// no trace_id — including non-JSON passthrough lines — are dropped.
TraceID string
// TimeFormat is the layout for the timestamp. Defaults to "15:04:05.000".
TimeFormat string
// NoTime omits the timestamp from the output entirely.
NoTime bool
// Location, when set, converts timestamps to this timezone before
// formatting. A nil Location uses the timestamp's own location.
Location *time.Location
// LevelStyles overrides how levels are rendered. Levels absent from the map
// fall back to DefaultLevelStyles; a nil map uses the defaults entirely.
LevelStyles map[zapcore.Level]LevelStyle
// OTELResource includes OpenTelemetry resource attributes (service.name,
// host.name, ...) as fields. They are dropped by default because they repeat
// identically on every line. Only affects OTEL log records.
OTELResource bool
// OTELFunc includes the function name (the code.function.name attribute) in
// the caller of OpenTelemetry log records. Dropped by default as it
// duplicates the source location.
OTELFunc bool
// contains filtered or unexported fields
}
Formatter renders a single zap JSON log line into a human-readable form.
func (*Formatter) Follow ¶
Follow tails the file at path (like tail -f), formatting new lines as they are appended. It handles truncation/rotation by reopening when the file shrinks. It blocks until ctx is canceled.
func (*Formatter) Format ¶
Format parses a single log line and returns its pretty representation.
The returned bool reports whether the line should be printed. Lines in none of the supported formats — zap and OTEL JSON, logfmt, klog — are returned unchanged (and ok is true) so that mixed output is preserved. Lines below MinLevel are dropped (ok is false).
func (*Formatter) Process ¶
Process reads newline-delimited logs from r, formats each line with f and writes the result to w until r is exhausted or ctx is canceled.
func (*Formatter) SetMinLevel ¶
SetMinLevel sets the minimum level to display.
type LevelStyle ¶
type LevelStyle struct {
// Label is the text shown for the level (e.g. "I" for info).
Label string
// Color is the ANSI escape sequence applied to the label. Empty means no
// color. Ignored when the Formatter has Color disabled.
Color string
}
LevelStyle controls how a single log level is rendered.