zap icon indicating copy to clipboard operation
zap copied to clipboard

JSON output extra characters (ANSI)

Open neumachen opened this issue 7 years ago • 2 comments

What could be causing this extra characters?

{"level":"\u001b[34minfo\u001b[0m","message":"...

neumachen avatar Jul 18 '18 23:07 neumachen

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.

jcorbin avatar Jul 19 '18 20:07 jcorbin

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)
 }

jcorbin avatar Jul 19 '18 20:07 jcorbin