Skip to content

Add SetPrefixFormatter to logger for customizable line decoration #4009

@tjayrush

Description

@tjayrush

The core logger hardcodes its prefix (severity + timestamp + optional color) inside toLog and only allows full decoration on/off via ToggleDecoration(). Embedding apps (e.g. servers with their own timestamps or structured logging) need finer control.

Proposal:

Add: // SetPrefixFormatter installs a callback run per log line. // Returning "" emits no prefix. Passing nil restores default. func SetPrefixFormatter(f func(sev Severity, t time.Time) string)
Default keeps current behavior (backward compatible).
ToggleDecoration can internally switch between default formatter and a no-op.
Document concurrency expectations (must be fast, thread-safe, minimal allocs).
Benefits:

Unify formatting across subsystems.
Allow removing duplicate timestamps.
Path toward structured / JSON logging.
Non-goals (initial):

Per-module log levels
Full structured logger replacement
Acceptance:

No behavior change if never called.
Tests: default unchanged; custom formatter applied.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions