diff --git a/benchmarks/go.mod b/benchmarks/go.mod index 7636b69..5bfafc0 100644 --- a/benchmarks/go.mod +++ b/benchmarks/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/apex/log v1.9.0 + github.com/khorevaa/logos v0.9.0 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 bd5976f..9b6f615 100644 --- a/benchmarks/go.sum +++ b/benchmarks/go.sum @@ -23,10 +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/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= -github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= -github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= -github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= +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/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= @@ -76,8 +74,6 @@ github.com/tj/go-buffer v1.1.0/go.mod h1:iyiJpfFcR2B9sXu7KvjbT9fpM4mOelRSDTbntVj github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eNAjXGDx2yma7uG2XoyRZTq1uv3M/o7imD0= github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao= github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= -github.com/khorevaa/logos v0.0.0-20210128201039-04350835b235 h1:bnt2KYugM3aTSE6VH4kRYFdFE0z18ch8kchQ4vtP0yU= -github.com/khorevaa/logos v0.0.0-20210128201039-04350835b235/go.mod h1:nhDpfkExY+70/vYt47VjnDulF6Tt5V17uNy3+Lsu7a8= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= diff --git a/benchmarks/main/main_test.go b/benchmarks/main/main_test.go index 80c9e95..43a4d45 100644 --- a/benchmarks/main/main_test.go +++ b/benchmarks/main/main_test.go @@ -18,9 +18,11 @@ func BenchmarkLogos(b *testing.B) { appenders: console: - name: CONSOLE + no_color: true target: discard encoder: console: + disable_colors: true loggers: root: level: info diff --git a/encoder/console/colorEncoder.go b/encoder/console/colorEncoder.go index f7a9f59..1675230 100644 --- a/encoder/console/colorEncoder.go +++ b/encoder/console/colorEncoder.go @@ -18,11 +18,12 @@ var poolColoredEncoder = sync.Pool{ }, } -func getColoredEncoder(lvlColor uint16, scheme ColorScheme) *coloredEncoder { +func getColoredEncoder(lvlColor uint16, scheme ColorScheme, disableColor bool) *coloredEncoder { enc := poolColoredEncoder.Get().(*coloredEncoder) enc.buf = bufferpool.Get() enc.scheme = scheme enc.entLevelColor = lvlColor + enc.disableColor = disableColor return enc } @@ -51,6 +52,7 @@ func putColoredEncoder(enc *coloredEncoder) { enc.scheme = defaultScheme enc.buf.Free() enc.entLevelColor = NoColor + enc.disableColor = false enc.EncodeDuration = nil enc.EncodeTime = nil poolColoredEncoder.Put(enc) diff --git a/encoder/console/console.go b/encoder/console/console.go index 31de6e0..46e65d4 100644 --- a/encoder/console/console.go +++ b/encoder/console/console.go @@ -149,13 +149,13 @@ func (e *Encoder) appendTimeInfo(buf *buffer.Buffer, entry zapcore.Entry) { } -func (e Encoder) writeContext(defColor uint16, out *buffer.Buffer, extra []zapcore.Field) { +func (e *Encoder) writeContext(defColor uint16, out *buffer.Buffer, extra []zapcore.Field) { if len(extra) == 0 { return } //e.buf.AppendByte('{') - enc := getColoredEncoder(defColor, e.Schema) + enc := getColoredEncoder(defColor, e.Schema, e.DisableColors) defer putColoredEncoder(enc) addFields(enc, extra) @@ -165,13 +165,13 @@ func (e Encoder) writeContext(defColor uint16, out *buffer.Buffer, extra []zapco } -func (e Encoder) addSeparatorIfNecessary(line *buffer.Buffer) { +func (e *Encoder) addSeparatorIfNecessary(line *buffer.Buffer) { if line.Len() > 0 { line.AppendString(e.ConsoleSeparator) } } -func (e Encoder) colorizeText(text string, color uint16) string { +func (e *Encoder) colorizeText(text string, color uint16) string { if e.DisableColors { return text