diff --git a/benchmarks/go.mod b/benchmarks/go.mod index 5bfafc0..0619690 100644 --- a/benchmarks/go.mod +++ b/benchmarks/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( github.com/apex/log v1.9.0 - github.com/khorevaa/logos v0.9.0 + github.com/khorevaa/logos v0.9.1 github.com/phuslu/log v1.0.60 github.com/rs/zerolog v1.20.0 github.com/sirupsen/logrus v1.7.0 diff --git a/benchmarks/go.sum b/benchmarks/go.sum index 9b6f615..4550256 100644 --- a/benchmarks/go.sum +++ b/benchmarks/go.sum @@ -23,8 +23,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0= -github.com/khorevaa/logos v0.9.0 h1:Yp63sQ+JXLoUy/SuNR+WBjJJOd70xqrSSzv6QJWxzj4= -github.com/khorevaa/logos v0.9.0/go.mod h1:wLXbpwEXx1Je5HTf7EwgbJntj2kGPvvvAEbxqWlOZNA= +github.com/khorevaa/logos v0.9.1 h1:ug4ut4svx2X+uxamm6mQRVCsFdr3mlSWRcLrzCvQZV0= +github.com/khorevaa/logos v0.9.1/go.mod h1:wLXbpwEXx1Je5HTf7EwgbJntj2kGPvvvAEbxqWlOZNA= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= diff --git a/encoder/console/console.go b/encoder/console/console.go index 46e65d4..9b6c5bd 100644 --- a/encoder/console/console.go +++ b/encoder/console/console.go @@ -154,13 +154,26 @@ func (e *Encoder) writeContext(defColor uint16, out *buffer.Buffer, extra []zapc if len(extra) == 0 { return } - //e.buf.AppendByte('{') - enc := getColoredEncoder(defColor, e.Schema, e.DisableColors) - defer putColoredEncoder(enc) + + var enc zapcore.ObjectEncoder + if !e.DisableColors { + enc = getColoredEncoder(defColor, e.Schema, e.DisableColors) + defer putColoredEncoder(enc.(*coloredEncoder)) + } else { + enc = e + } addFields(enc, extra) - if enc.buf.Len() > 0 { - out.Write(enc.buf.Bytes()) + var buf *buffer.Buffer + switch t := enc.(type) { + case *Encoder: + buf = t.buf + case *coloredEncoder: + buf = t.buf + } + + if buf.Len() > 0 { + out.Write(buf.Bytes()) } }