Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions core/logger/internal/colortest/prettyconsole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package colortest
import (
"testing"

"github.com/smartcontractkit/chainlink/core/logger"
"github.com/stretchr/testify/assert"

"github.com/smartcontractkit/chainlink/core/logger"
)

func init() {
Expand All @@ -19,24 +20,48 @@ func TestPrettyConsole_Write(t *testing.T) {
wantError bool
}{
{
"headline",
`{"ts":1523537728.7260377, "level":"info", "msg":"top level"}`,
"2018-04-12T12:55:28Z \x1b[37m[INFO] \x1b[0mtop level \x1b[34m\x1b[0m \n",
"debug",
`{"ts":1523537728, "level":"debug", "msg":"top level", "details":"nuances"}`,
"2018-04-12T12:55:28Z \x1b[32m[DEBUG] \x1b[0mtop level \x1b[34m\x1b[0m \x1b[32mdetails\x1b[0m=nuances \n",
false,
},
{
"details",
`{"ts":1523537728, "level":"debug", "msg":"top level", "details":"nuances"}`,
"2018-04-12T12:55:28Z \x1b[32m[DEBUG] \x1b[0mtop level \x1b[34m\x1b[0m \x1b[32mdetails\x1b[0m=nuances \n",
"info",
`{"ts":1523537728.7260377, "level":"info", "msg":"top level"}`,
"2018-04-12T12:55:28Z \x1b[37m[INFO] \x1b[0mtop level \x1b[34m\x1b[0m \n",
false,
},
{
"blacklist",
"warn",
`{"ts":1523537728, "level":"warn", "msg":"top level", "hash":"nuances"}`,
"2018-04-12T12:55:28Z \x1b[33m[WARN] \x1b[0mtop level \x1b[34m\x1b[0m \n",
false,
},
{"error", `{"broken":}`, `{}`, true},
{
"error",
`{"ts":1523537728, "level":"error", "msg":"top level", "hash":"nuances"}`,
"2018-04-12T12:55:28Z \x1b[31m[ERROR] \x1b[0mtop level \x1b[34m\x1b[0m \n",
false,
},
{
"critical",
`{"ts":1523537728, "level":"crit", "msg":"top level", "hash":"nuances"}`,
"2018-04-12T12:55:28Z \x1b[91m[CRIT] \x1b[0mtop level \x1b[34m\x1b[0m \n",
false,
},
{
"panic",
`{"ts":1523537728, "level":"panic", "msg":"top level", "hash":"nuances"}`,
"2018-04-12T12:55:28Z \x1b[91m[PANIC] \x1b[0mtop level \x1b[34m\x1b[0m \n",
false,
},
{
"fatal",
`{"ts":1523537728, "level":"fatal", "msg":"top level", "hash":"nuances"}`,
"2018-04-12T12:55:28Z \x1b[91m[FATAL] \x1b[0mtop level \x1b[34m\x1b[0m \n",
false,
},
{"broken", `{"broken":}`, `{}`, true},
}

for _, tt := range tests {
Expand All @@ -48,6 +73,7 @@ func TestPrettyConsole_Write(t *testing.T) {
if tt.wantError {
assert.Error(t, err)
} else {
t.Log(tr.Written)
assert.Equal(t, tt.want, tr.Written)
}
})
Expand Down
5 changes: 3 additions & 2 deletions core/logger/prettyconsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ var levelColors = map[string]func(...interface{}) string{
"info": color.New(color.FgWhite).SprintFunc(),
"warn": color.New(color.FgYellow).SprintFunc(),
"error": color.New(color.FgRed).SprintFunc(),
"panic": color.New(color.FgRed).SprintFunc(),
"fatal": color.New(color.FgRed).SprintFunc(),
"panic": color.New(color.FgHiRed).SprintFunc(),
"crit": color.New(color.FgHiRed).SprintFunc(),
"fatal": color.New(color.FgHiRed).SprintFunc(),
}

var blue = color.New(color.FgBlue).SprintFunc()
Expand Down
8 changes: 1 addition & 7 deletions core/logger/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,7 @@ func makeEncoderConfig(cfg Config) zapcore.EncoderConfig {
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
}

encoderConfig.EncodeLevel = func(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
if l == zapcore.DPanicLevel {
enc.AppendString("crit")
} else {
zapcore.LowercaseLevelEncoder(l, enc)
}
}
encoderConfig.EncodeLevel = encodeLevel

return encoderConfig
}
Expand Down