Skip to content

Commit 2a23dc7

Browse files
authored
Improve logs (#16075)
**What type of PR is this?** Other **What does this PR do? Why is it needed?** - Added log prefix to the `genesis` package. - Added log prefix to the `params` package. - `WithGenesisValidatorsRoot`: Use camelCase for log field param. - Move `Origin checkpoint found in db` log from WARN to INFO, since it is the expected behaviour. **Other notes for review** Please read commit by commit **Acknowledgements** - [x] I have read [CONTRIBUTING.md](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md). - [x] I have included a uniquely named [changelog fragment file](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md#maintaining-changelogmd). - [x] I have added a description to this PR with sufficient context for reviewers to understand this PR.
1 parent f97622b commit 2a23dc7

File tree

11 files changed

+27
-12
lines changed

11 files changed

+27
-12
lines changed

beacon-chain/sync/checkpoint/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func NewAPIInitializer(beaconNodeHost string) (*APIInitializer, error) {
4444
func (dl *APIInitializer) Initialize(ctx context.Context, d db.Database) error {
4545
origin, err := d.OriginCheckpointBlockRoot(ctx)
4646
if err == nil && origin != params.BeaconConfig().ZeroHash {
47-
log.Warnf("Origin checkpoint root %#x found in db, ignoring checkpoint sync flags", origin)
47+
log.WithField("root", fmt.Sprintf("%#x", origin)).Info("Origin checkpoint found in the database, ignoring checkpoint sync flags")
4848
return nil
4949
}
5050
if err != nil && !errors.Is(err, db.ErrNotFound) {

beacon-chain/sync/checkpoint/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type FileInitializer struct {
4444
func (fi *FileInitializer) Initialize(ctx context.Context, d db.Database) error {
4545
origin, err := d.OriginCheckpointBlockRoot(ctx)
4646
if err == nil && origin != params.BeaconConfig().ZeroHash {
47-
log.Warnf("Origin checkpoint root %#x found in db, ignoring checkpoint sync flags", origin)
47+
log.WithField("root", fmt.Sprintf("%#x", origin)).Info("Origin checkpoint found in the database, ignoring checkpoint sync flags")
4848
return nil
4949
} else {
5050
if !errors.Is(err, db.ErrNotFound) {

changelog/manu-logs.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Changed
2+
3+
- Added log prefix to the `genesis` package.
4+
- Added log prefix to the `params` package.
5+
- `WithGenesisValidatorsRoot`: Use camelCase for log field param.
6+
- Move `Origin checkpoint found in db` from WARN to INFO, since it is the expected behaviour.

cmd/beacon-chain/genesis/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library")
22

33
go_library(
44
name = "go_default_library",
5-
srcs = ["options.go"],
5+
srcs = [
6+
"log.go",
7+
"options.go",
8+
],
69
importpath = "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/genesis",
710
visibility = ["//visibility:public"],
811
deps = [

cmd/beacon-chain/genesis/log.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package genesis
2+
3+
import "github.com/sirupsen/logrus"
4+
5+
var log = logrus.WithField("prefix", "genesis")

cmd/beacon-chain/genesis/options.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/sync/checkpoint"
66
"github.com/OffchainLabs/prysm/v7/genesis"
77
"github.com/pkg/errors"
8-
log "github.com/sirupsen/logrus"
98
"github.com/urfave/cli/v2"
109
)
1110

config/params/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ go_library(
1414
"interop.go",
1515
"io_config.go",
1616
"loader.go",
17+
"log.go",
1718
"mainnet_config.go",
1819
"minimal_config.go",
1920
"network_config.go",

config/params/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"sync"
1111
"time"
1212

13-
log "github.com/sirupsen/logrus"
14-
1513
fieldparams "github.com/OffchainLabs/prysm/v7/config/fieldparams"
1614
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
1715
"github.com/OffchainLabs/prysm/v7/crypto/hash"
@@ -20,6 +18,7 @@ import (
2018
"github.com/OffchainLabs/prysm/v7/runtime/version"
2119
"github.com/ethereum/go-ethereum/common"
2220
"github.com/pkg/errors"
21+
"github.com/sirupsen/logrus"
2322
)
2423

2524
// BeaconChainConfig contains constant configs for node to participate in beacon chain.
@@ -359,15 +358,15 @@ type NetworkScheduleEntry struct {
359358
isFork bool `yaml:"-" json:"-"`
360359
}
361360

362-
func (e NetworkScheduleEntry) LogFields() log.Fields {
361+
func (e NetworkScheduleEntry) LogFields() logrus.Fields {
363362
gvr := BeaconConfig().GenesisValidatorsRoot
364363
root, err := computeForkDataRoot(e.ForkVersion, gvr)
365364
if err != nil {
366365
log.WithField("version", fmt.Sprintf("%#x", e.ForkVersion)).
367366
WithField("genesisValidatorsRoot", fmt.Sprintf("%#x", gvr)).
368367
WithError(err).Error("Failed to compute fork data root")
369368
}
370-
fields := log.Fields{
369+
fields := logrus.Fields{
371370
"forkVersion": fmt.Sprintf("%#x", e.ForkVersion),
372371
"forkDigest": fmt.Sprintf("%#x", e.ForkDigest),
373372
"maxBlobsPerBlock": e.MaxBlobsPerBlock,

config/params/loader.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
1111
"github.com/OffchainLabs/prysm/v7/math"
1212
"github.com/pkg/errors"
13-
log "github.com/sirupsen/logrus"
1413
"gopkg.in/yaml.v2"
1514
)
1615

config/params/log.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package params
2+
3+
import "github.com/sirupsen/logrus"
4+
5+
var log = logrus.WithField("prefix", "params")

0 commit comments

Comments
 (0)