Skip to content

Add configurable logTimeFormat option (#515, #427)#568

Open
dolonet wants to merge 1 commit into
masterfrom
log-time-format
Open

Add configurable logTimeFormat option (#515, #427)#568
dolonet wants to merge 1 commit into
masterfrom
log-time-format

Conversation

@dolonet

@dolonet dolonet commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

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 TypeLogTimeFormat wrapper in internal/config, modeled on the
    existing typed fields (Set/Get/UnmarshalText/String), plus a
    ZerologFormat() 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-mszerolog.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.toml documents 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 with prefer-ip and the other
    optional string fields); Set() rejects empty at the type level.
  • Behavior: makeLogger sets zerolog.TimeFieldFormat to 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.

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.
@alexeys85

Copy link
Copy Markdown

It would be nice to have an option to output log to file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

timezone is not honored in log Формат времени

2 participants