Skip to content

Custom timestamp field #1129

Answered by happybydefault
apremalal asked this question in Q&A
Aug 1, 2017 · 11 comments · 2 replies
Discussion options

You must be logged in to vote

I think this is the best way, as you can use any Go time layout string you want:

config := zap.NewProductionConfig() // or zap.NewDevelopmentConfig() or any other zap.Config
config.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout(time.RFC3339) // or time.RubyDate or "2006-01-02 15:04:05" or even freaking time.Kitchen

logger, err := config.Build()

For more information on how to format the layout string, check https://pkg.go.dev/time#pkg-constants

Replies: 11 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mway
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@abhinav
Comment options

@cschar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #485 on July 12, 2022 23:13.