refactor(log): disable coloring in testing logger (#22466)

This commit is contained in:
Julien Robert
2024-11-07 13:13:48 +00:00
committed by GitHub
parent f6c7ab68e7
commit ffa74d17cb
4 changed files with 23 additions and 15 deletions
+4 -3
View File
@@ -22,10 +22,11 @@ Each entry must include the Github issue reference in the following format:
## [Unreleased]
### Improvements
## [v1.5.0](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.4.1) - 2024-11-07
* [#22233](https://github.com/cosmos/cosmos-sdk/pull/22233) Use sonic json library for faster json handling
* [#22347](https://github.com/cosmos/cosmos-sdk/pull/22347) Add cosmossdk.io/log/slog to allow using a standard library log/slog-backed logger.
* [#22466](https://github.com/cosmos/cosmos-sdk/pull/22466) Disable coloring in testing logger.
* [#22233](https://github.com/cosmos/cosmos-sdk/pull/22233) Use sonic json library for faster json handling.
* [#22347](https://github.com/cosmos/cosmos-sdk/pull/22347) Add `cosmossdk.io/log/slog` to allow using a standard library log/slog-backed logger. This required to bump the minimum go version of `cosmossdk.io/log` to 1.21.
## [v1.4.1](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.4.1) - 2024-08-16
+1 -1
View File
@@ -1,6 +1,6 @@
module cosmossdk.io/log
go 1.20
go 1.21
require (
github.com/bytedance/sonic v1.12.3
+17 -10
View File
@@ -1,6 +1,10 @@
package log
import "github.com/rs/zerolog"
import (
"time"
"github.com/rs/zerolog"
)
// TestingT is the interface required for logging in tests.
// It is a subset of testing.T to avoid a direct dependency on the testing package.
@@ -39,15 +43,18 @@ func NewTestLoggerError(t TestingT) Logger {
}
func newTestLogger(t TestingT, lvl zerolog.Level) Logger {
cw := zerolog.NewConsoleWriter()
cw.Out = zerolog.TestWriter{
T: t,
// Normally one would use zerolog.ConsoleTestWriter
// to set the option on NewConsoleWriter,
// but the zerolog source for that is hardcoded to Frame=6.
// With Frame=6, all source locations are printed as "logger.go",
// but Frame=7 prints correct source locations.
Frame: 7,
cw := zerolog.ConsoleWriter{
NoColor: true,
TimeFormat: time.Kitchen,
Out: zerolog.TestWriter{
T: t,
// Normally one would use zerolog.ConsoleTestWriter
// to set the option on NewConsoleWriter,
// but the zerolog source for that is hardcoded to Frame=6.
// With Frame=6, all source locations are printed as "logger.go",
// but Frame=7 prints correct source locations.
Frame: 7,
},
}
return NewCustomLogger(zerolog.New(cw).Level(lvl))
}