log: add utility to reset global state

This commit is contained in:
Martin Holst Swende 2023-10-20 10:40:41 +02:00
parent dbf3b708bb
commit debb1e7d89
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 9 additions and 0 deletions

View file

@ -31,6 +31,7 @@ import (
// logTest is an entry point which spits out some logs. This is used by testing // logTest is an entry point which spits out some logs. This is used by testing
// to verify expected outputs // to verify expected outputs
func logTest(ctx *cli.Context) error { func logTest(ctx *cli.Context) error {
log.ResetGlobalState()
{ // big.Int { // big.Int
ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999" ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999"
bb, _ := new(big.Int).SetString("-111222333444555678999", 10) // "-111,222,333,444,555,678,999" bb, _ := new(big.Int).SetString("-111222333444555678999", 10) // "-111,222,333,444,555,678,999"

View file

@ -24,6 +24,14 @@ const (
termCtxMaxPadding = 40 termCtxMaxPadding = 40
) )
// ResetGlobalState resets the fieldPadding, which is useful for producing
// predictable output.
func ResetGlobalState() {
fieldPaddingLock.Lock()
fieldPadding = make(map[string]int)
fieldPaddingLock.Unlock()
}
// locationTrims are trimmed for display to avoid unwieldy log lines. // locationTrims are trimmed for display to avoid unwieldy log lines.
var locationTrims = []string{ var locationTrims = []string{
"github.com/ethereum/go-ethereum/", "github.com/ethereum/go-ethereum/",