Add configurable logTimeFormat option (#515, #427)
What
Adds a logTimeFormat config option so the log timestamp format is
configurable instead of hardcoded to Unix milliseconds.
internal/cli/run_proxy.go previously did
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs unconditionally.
That value carries no timezone, so on plain log viewers (podman logs,
logread on OpenWRT) it reads as UTC and the host TZ is ignored —
exactly what #515 reports, and the long-standing ask in #427.
Approach
Based on the approach of #531 by @resolvicomai — same field name
(logTimeFormat), same preset set, default unix-ms, Go-layout
passthrough. I reworked it to address the review nit on that PR
(a bare string field) by giving it a proper typed wrapper, matching
how every other config field is modeled, and added focused tests.
Credit for the original shape is theirs.
This matches the design you approved on #515.
Details
- New
TypeLogTimeFormatwrapper ininternal/config, modeled on the existing typed fields (Set/Get/UnmarshalText/String), plus aZerologFormat()resolver that maps presets to zerolog constants. - Presets:
unix,unix-ms,unix-micro,unix-nano,rfc3339,rfc3339-nano. Anything else is passed through as a Go reference-time layout. - Default is
unix-ms→zerolog.TimeFormatUnixMs, so the current log output is byte-for-byte unchanged unless the option is set. Set()rejects an empty value (fail-fast on config load). Go layouts are permissive strings, so validation beyond "known preset or non-empty" isn't reliably possible — documented on the type.example.config.tomldocuments the presets; all example values render the same instant (2026-05-20T12:23:45.123Z).
Omitted: iso8601 (always-UTC)
zerolog formats the layout against the timestamp's own location; there's
no native always-UTC constant, and forcing it would need a custom
TimestampFunc/hook. I left it out rather than ship something fragile —
the numeric presets already give an always-UTC option, and rfc3339
gives the TZ-aware one. Happy to add it if you'd like a specific shape.
Tests
- Config parsing: each preset parses; default is
unix-ms; empty value behaves as unset→default (consistent withprefer-ipand the other optional string fields);Set()rejects empty at the type level. - Behavior:
makeLoggersetszerolog.TimeFieldFormatto the resolved preset/layout, including the unchanged default. - No network/httpbin-dependent tests.
go build ./..., go test ./internal/... -race, and
golangci-lint run (v2) are all clean locally.
Ready for your review, no rush.
Fixes #515. Resolves #427.
It would be nice to have an option to output log to file.