Add configurable logTimeFormat option (#515, #427)#568
Open
dolonet wants to merge 1 commit into
Open
Conversation
Logs hardcoded timestamps as Unix milliseconds, which carries no timezone and reads as UTC in plain log viewers (podman logs, logread). This adds a logTimeFormat config field so operators can pick a TZ-aware format, while keeping the existing numeric output as default. - New TypeLogTimeFormat wrapper (typed like every other config field): presets unix / unix-ms / unix-micro / unix-nano / rfc3339 / rfc3339-nano, and any other value is passed through to zerolog as a Go reference-time layout. Set() rejects an empty value. - Default stays "unix-ms" -> zerolog.TimeFormatUnixMs, so output is byte-for-byte unchanged unless the option is set. - run_proxy.go resolves the configured value instead of hardcoding it. - example.config.toml documents the presets with a single consistent example instant. Based on the approach of #531 by @resolvicomai. Resolves #427.
|
It would be nice to have an option to output log to file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
logTimeFormatconfig option so the log timestamp format isconfigurable instead of hardcoded to Unix milliseconds.
internal/cli/run_proxy.gopreviously didzerolog.TimeFieldFormat = zerolog.TimeFormatUnixMsunconditionally.That value carries no timezone, so on plain log viewers (
podman logs,logreadon OpenWRT) it reads as UTC and the hostTZis 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, defaultunix-ms, Go-layoutpassthrough. I reworked it to address the review nit on that PR
(a bare
stringfield) by giving it a proper typed wrapper, matchinghow 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
TypeLogTimeFormatwrapper ininternal/config, modeled on theexisting typed fields (
Set/Get/UnmarshalText/String), plus aZerologFormat()resolver that maps presets to zerolog constants.unix,unix-ms,unix-micro,unix-nano,rfc3339,rfc3339-nano. Anything else is passed through as a Go reference-timelayout.
unix-ms→zerolog.TimeFormatUnixMs, so the currentlog output is byte-for-byte unchanged unless the option is set.
Set()rejects an empty value (fail-fast on config load). Go layoutsare 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 valuesrender 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
rfc3339gives the TZ-aware one. Happy to add it if you'd like a specific shape.
Tests
unix-ms; empty valuebehaves as unset→default (consistent with
prefer-ipand the otheroptional string fields);
Set()rejects empty at the type level.makeLoggersetszerolog.TimeFieldFormatto the resolvedpreset/layout, including the unchanged default.
go build ./...,go test ./internal/... -race, andgolangci-lint run(v2) are all clean locally.Ready for your review, no rush.
Fixes #515.
Resolves #427.