trueblocks-core icon indicating copy to clipboard operation
trueblocks-core copied to clipboard

Add SetPrefixFormatter to logger for customizable line decoration

Open tjayrush opened this issue 4 months ago • 0 comments

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.

tjayrush avatar Aug 21 '25 12:08 tjayrush