Skip to content

fix(zapcore): fall back to default Encode* implementations when nil#1551

Open
leno23 wants to merge 1 commit into
uber-go:masterfrom
leno23:fix/encoder-nil-fallback
Open

fix(zapcore): fall back to default Encode* implementations when nil#1551
leno23 wants to merge 1 commit into
uber-go:masterfrom
leno23:fix/encoder-nil-fallback

Conversation

@leno23

@leno23 leno23 commented May 25, 2026

Copy link
Copy Markdown

Summary

  • When EncoderConfig sets LevelKey, TimeKey, or CallerKey but leaves the matching Encode* function nil, newJSONEncoder now applies the same defaults used elsewhere (LowercaseLevelEncoder, EpochTimeEncoder, ShortCallerEncoder)
  • Removes the hard config.Build() failure for missing EncodeTime in EncoderConfig; nil duration encoding already had a runtime fallback via AppendDuration
  • Adds regression coverage for nil EncodeLevel/EncodeTime/EncodeDuration/EncodeCaller and for building a config with TimeKey set but no custom encoder

Test plan

  • go test ./...
  • Verified custom EncodeTime still works with "console" encoding (issue repro)

Fixes #537

When EncoderConfig sets LevelKey, TimeKey, or CallerKey but leaves the
corresponding encoder function nil, use the same defaults as an empty
config instead of failing config.Build or omitting metadata.

Fixes uber-go#537

Co-authored-by: Cursor <cursoragent@cursor.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


wuyangfan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Encoders should fall back to default Encode* implementations

2 participants