Merge pull request #5 from danielgtaylor/lg/timestamps

feat: add iso8601 timestamps to logging
This commit is contained in:
Logan Garrett 2020-06-26 12:26:50 -07:00 committed by GitHub
commit d7e3237de2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -135,14 +135,21 @@ func NewLogger() (*zap.Logger, error) {
config := zap.NewDevelopmentConfig()
logLevel = &config.Level
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
config.EncoderConfig.EncodeTime = iso8601UTCTimeEncoder
return config.Build()
}
config := zap.NewProductionConfig()
config.EncoderConfig.EncodeTime = iso8601UTCTimeEncoder
logLevel = &config.Level
return config.Build()
}
// A UTC variation of ZapCore.ISO8601TimeEncoder with millisecond precision
func iso8601UTCTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.UTC().Format("2006-01-02T15:04:05.000Z"))
}
// LogOption is used to set optional configuration for logging.
type LogOption func(*zap.Logger) *zap.Logger