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

fix: fix colorize with encoder

This commit is contained in:
khorevaa 2021-02-02 17:52:39 +03:00
parent fae54740e4
commit ce77d721ff
5 changed files with 12 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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