zap
zap copied to clipboard
JSON output extra characters (ANSI)
What could be causing this extra characters?
{"level":"\u001b[34minfo\u001b[0m","message":"...
You've somehow configured the encoder ( https://godoc.org/go.uber.org/zap/zapcore#EncoderConfig ) to use colored level encoding within json encoding; colored level encoding was intended only for use under .the console encoder.
cc @akshayjshah is there anything we could do to protect users from this sort of config? Ala:
diff --git a/zapcore/json_encoder.go b/zapcore/json_encoder.go
index 2dc67d8..a04a929 100644
--- a/zapcore/json_encoder.go
+++ b/zapcore/json_encoder.go
@@ -78,6 +78,9 @@ type jsonEncoder struct {
// pair) when unmarshaling, but users should attempt to avoid adding duplicate
// keys.
func NewJSONEncoder(cfg EncoderConfig) Encoder {
+ // TODO panic or stash an advisory warning flag away if
+ // cfg.EncodeLevel == LowercaseColorLevelEncoder or
+ // cfg.EncodeLevel == CapitalColorLevelEncoder
return newJSONEncoder(cfg, false)
}