Skip to content

fix(console): omit missing timestamp instead of printing <nil> - #778

Open
Solaris-star wants to merge 1 commit into
rs:masterfrom
Solaris-star:fix/725-console-nil-timestamp
Open

fix(console): omit missing timestamp instead of printing <nil>#778
Solaris-star wants to merge 1 commit into
rs:masterfrom
Solaris-star:fix/725-console-nil-timestamp

Conversation

@Solaris-star

Copy link
Copy Markdown

Description

When a logger is created without .Timestamp(), ConsoleWriter still reserved a timestamp column and printed the literal string <nil>:

<nil> INF Batch size exceeded...

This is common in Docker/container setups and looks like a broken clock.

Fix

In consoleDefaultFormatTimestamp, return an empty string when the timestamp value is nil. writePart already skips empty parts and only inserts spacing between non-empty parts.

Tests

go test ./... -count=1
# all packages ok

Added TestConsoleWriterOmitsNilTimestamp.

Linked Issue

Closes #725

ConsoleWriter always rendered a missing time field as the literal
string "<nil>", which is especially confusing in Docker/container logs
when the logger was created without .Timestamp().

Treat a nil timestamp value as empty so the part is skipped (spacing
already handles empty parts).

Fixes rs#725
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.

<nil> timestamp when running in docker

1 participant