Skip to content

Commit

Permalink
refactor(log): disable coloring in testing logger (#22466)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Nov 7, 2024
1 parent f6c7ab6 commit ffa74d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.21"
check-latest: true
cache: true
cache-dependency-path: log/go.sum
Expand Down
7 changes: 4 additions & 3 deletions log/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion log/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module cosmossdk.io/log

go 1.20
go 1.21

require (
github.com/bytedance/sonic v1.12.3
Expand Down
27 changes: 17 additions & 10 deletions log/testing.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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))
}

0 comments on commit ffa74d1

Please # to comment.