-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package log | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func newTextFormatterConfig(cfg *Config) zap.Config { | ||
var zc zap.Config | ||
|
||
zc = zap.NewProductionConfig() | ||
|
||
if cfg.useColour { | ||
zc.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder | ||
} | ||
zc.EncoderConfig.CallerKey = "" | ||
zc.EncoderConfig.FunctionKey = "" | ||
zc.EncoderConfig.ConsoleSeparator = " " | ||
zc.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout("15:04:05") | ||
zc.EncoderConfig.EncodeDuration = zapcore.StringDurationEncoder | ||
zc.Level.SetLevel(cfg.logLevel.zapLevel()) | ||
zc.Encoding = cfg.formatter | ||
|
||
// we don't want zap stacktraces because they are incredibly noisy | ||
zc.DisableStacktrace = true | ||
return zc | ||
} | ||
|
||
func newJSONFormatterConfig(cfg *Config) zap.Config { | ||
var zc zap.Config | ||
zc = zap.NewProductionConfig() | ||
// We want log.Duration("duration", ...) to naturally map to Datadog's 'duration' standard attribute. | ||
// Datadog displays it nicely and uses it as a default measure for trace search. | ||
// See https://docs.datadoghq.com/logs/log_configuration/attributes_naming_convention/#performance | ||
// The spec requires that it be encoded in nanoseconds (default is seconds). | ||
zc.EncoderConfig.EncodeDuration = zapcore.NanosDurationEncoder | ||
zc.Level.SetLevel(cfg.logLevel.zapLevel()) | ||
zc.Encoding = cfg.formatter | ||
// we don't want zap stacktraces because they are incredibly noisy | ||
zc.DisableStacktrace = true | ||
return zc | ||
} |