1
0
mirror of https://github.com/khorevaa/logos.git synced 2024-11-24 08:52:19 +02:00

fix: fix colorize with encoder context

This commit is contained in:
khorevaa 2021-02-02 18:01:41 +03:00
parent ce77d721ff
commit eec1c89bcd
3 changed files with 21 additions and 8 deletions

View File

@ -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

View File

@ -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=

View File

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