From 38b4faa6de04a95df46753580b93aab0b7156804 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 27 Apr 2019 12:03:18 -0700 Subject: [PATCH] Add block logger --- core/types/block.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/types/block.go b/core/types/block.go index 51844d74d..c23fc5be9 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "golang.org/x/crypto/sha3" @@ -485,3 +486,16 @@ func (b *Block) AddShardState(shardState ShardState) { b.header.ShardStateHash = shardState.Hash() b.header.ShardState = shardState } + +// Logger returns a sub-logger with block contexts added. +func (b *Block) Logger(logger log.Logger) log.Logger { + // Avoid using b.Hash() 'cause it fixates/caches calculated hash into the + // block and we don't want to fixate a premature hash from a half-built + // header. + return logger.New( + "blockHash", b.header.Hash(), + "blockShard", b.header.ShardID, + "blockEpoch", b.header.Epoch, + "blockNumber", b.header.Number, + ) +}