diff --git a/cmd/go-quai/main.go b/cmd/go-quai/main.go index 2bf06bac3b..cdc74a74ca 100644 --- a/cmd/go-quai/main.go +++ b/cmd/go-quai/main.go @@ -31,10 +31,11 @@ import ( "github.com/dominant-strategies/go-quai/internal/debug" "github.com/dominant-strategies/go-quai/internal/flags" "github.com/dominant-strategies/go-quai/internal/quaiapi" - "github.com/dominant-strategies/go-quai/log" "github.com/dominant-strategies/go-quai/metrics" "github.com/dominant-strategies/go-quai/node" "github.com/dominant-strategies/go-quai/params" + "github.com/dominant-strategies/go-quai/log" + "gopkg.in/urfave/cli.v1" ) @@ -47,7 +48,7 @@ var ( gitCommit = "" gitDate = "" // The app that holds all commands and flags. - app = flags.NewApp(gitCommit, gitDate, "the go-ethereum command line interface") + app = flags.NewApp(gitCommit, gitDate, "the go-quai command line interface") // flags that configure the node nodeFlags = []cli.Flag{ utils.IdentityFlag, @@ -229,6 +230,7 @@ func prepare(ctx *cli.Context) { case !ctx.GlobalIsSet(utils.NetworkIdFlag.Name): netname = "Colosseum testnet" } + welcome := fmt.Sprintf("Starting Quai %s on %s", params.Version.Full(), netname) log.Info(welcome) // If we're a full node on colosseum without --cache specified, bump default cache allowance @@ -261,6 +263,9 @@ func quai(ctx *cli.Context) error { return fmt.Errorf("invalid command: %q", args[0]) } + // Setup logger. + log.ConfigureLogger(ctx) + prepare(ctx) stack, backend := makeFullNode(ctx) defer stack.Close() diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a6800364d4..a441977f51 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -719,7 +719,7 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) { if url != "" { node, err := enode.Parse(enode.ValidSchemes, url+cfg.ListenAddr) if err != nil { - log.Crit("Bootstrap URL invalid", "enode", url, "err", err) + log.Fatal("Bootstrap URL invalid", "enode", url, "err", err) continue } cfg.BootstrapNodes = append(cfg.BootstrapNodes, node) @@ -1232,7 +1232,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) { func SetGlobalVars(ctx *cli.Context) { // Configure global NodeLocation if !ctx.GlobalIsSet(RegionFlag.Name) && ctx.GlobalIsSet(ZoneFlag.Name) { - log.Crit("zone idx given, but missing region idx!") + log.Fatal("zone idx given, but missing region idx!") } if ctx.GlobalIsSet(RegionFlag.Name) { region := ctx.GlobalInt(RegionFlag.Name) diff --git a/consensus/blake3pow/blake3pow.go b/consensus/blake3pow/blake3pow.go index 1e3c0bffa6..9a110a1288 100644 --- a/consensus/blake3pow/blake3pow.go +++ b/consensus/blake3pow/blake3pow.go @@ -75,7 +75,7 @@ type Blake3pow struct { // packages. func New(config Config, notify []string, noverify bool) *Blake3pow { if config.Log == nil { - config.Log = log.Root() + config.Log = log.Log } blake3pow := &Blake3pow{ config: config, @@ -102,7 +102,7 @@ func NewFaker() *Blake3pow { return &Blake3pow{ config: Config{ PowMode: ModeFake, - Log: log.Root(), + Log: log.Log, }, } } @@ -114,7 +114,7 @@ func NewFakeFailer(fail uint64) *Blake3pow { return &Blake3pow{ config: Config{ PowMode: ModeFake, - Log: log.Root(), + Log: log.Log, }, fakeFail: fail, } @@ -127,7 +127,7 @@ func NewFakeDelayer(delay time.Duration) *Blake3pow { return &Blake3pow{ config: Config{ PowMode: ModeFake, - Log: log.Root(), + Log: log.Log, }, fakeDelay: delay, } @@ -139,7 +139,7 @@ func NewFullFaker() *Blake3pow { return &Blake3pow{ config: Config{ PowMode: ModeFullFake, - Log: log.Root(), + Log: log.Log, }, } } diff --git a/consensus/blake3pow/sealer.go b/consensus/blake3pow/sealer.go index 2ccd62e63b..6ed827cc04 100644 --- a/consensus/blake3pow/sealer.go +++ b/consensus/blake3pow/sealer.go @@ -17,6 +17,7 @@ import ( "github.com/dominant-strategies/go-quai/common" "github.com/dominant-strategies/go-quai/common/hexutil" "github.com/dominant-strategies/go-quai/core/types" + "github.com/dominant-strategies/go-quai/log" ) const ( @@ -122,7 +123,7 @@ func (blake3pow *Blake3pow) mine(header *types.Header, id int, seed uint64, abor nonce = seed powBuffer = new(big.Int) ) - logger := blake3pow.config.Log.New("miner", id) + logger := log.Log logger.Trace("Started blake3pow search for new nonces", "seed", seed) search: for { diff --git a/core/chain_indexer.go b/core/chain_indexer.go index 3856d026f3..2d514daba3 100644 --- a/core/chain_indexer.go +++ b/core/chain_indexer.go @@ -107,7 +107,7 @@ func NewChainIndexer(chainDb ethdb.Database, indexDb ethdb.Database, backend Cha sectionSize: section, confirmsReq: confirm, throttling: throttling, - log: log.New("type", kind), + log: log.Log, } // Initialize database dependent fields and start the updater c.loadValidSections() diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 869361db3e..caf21dc6e2 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -45,14 +45,14 @@ func ReadCanonicalHash(db ethdb.Reader, number uint64) common.Hash { // WriteCanonicalHash stores the hash assigned to a canonical block number. func WriteCanonicalHash(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { if err := db.Put(headerHashKey(number), hash.Bytes()); err != nil { - log.Crit("Failed to store number to hash mapping", "err", err) + log.Fatal("Failed to store number to hash mapping", "err", err) } } // DeleteCanonicalHash removes the number to hash canonical mapping. func DeleteCanonicalHash(db ethdb.KeyValueWriter, number uint64) { if err := db.Delete(headerHashKey(number)); err != nil { - log.Crit("Failed to delete number to hash mapping", "err", err) + log.Fatal("Failed to delete number to hash mapping", "err", err) } } @@ -121,14 +121,14 @@ func WriteHeaderNumber(db ethdb.KeyValueWriter, hash common.Hash, number uint64) key := headerNumberKey(hash) enc := encodeBlockNumber(number) if err := db.Put(key, enc); err != nil { - log.Crit("Failed to store hash to number mapping", "err", err) + log.Fatal("Failed to store hash to number mapping", "err", err) } } // DeleteHeaderNumber removes hash->number mapping. func DeleteHeaderNumber(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Delete(headerNumberKey(hash)); err != nil { - log.Crit("Failed to delete hash to number mapping", "err", err) + log.Fatal("Failed to delete hash to number mapping", "err", err) } } @@ -144,7 +144,7 @@ func ReadHeadHeaderHash(db ethdb.KeyValueReader) common.Hash { // WriteHeadHeaderHash stores the hash of the current canonical head header. func WriteHeadHeaderHash(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Put(headHeaderKey, hash.Bytes()); err != nil { - log.Crit("Failed to store last header's hash", "err", err) + log.Fatal("Failed to store last header's hash", "err", err) } } @@ -160,7 +160,7 @@ func ReadHeadBlockHash(db ethdb.KeyValueReader) common.Hash { // WriteHeadBlockHash stores the head block's hash. func WriteHeadBlockHash(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Put(headBlockKey, hash.Bytes()); err != nil { - log.Crit("Failed to store last block's hash", "err", err) + log.Fatal("Failed to store last block's hash", "err", err) } } @@ -183,10 +183,10 @@ func ReadLastPivotNumber(db ethdb.KeyValueReader) *uint64 { func WriteLastPivotNumber(db ethdb.KeyValueWriter, pivot uint64) { enc, err := rlp.EncodeToBytes(pivot) if err != nil { - log.Crit("Failed to encode pivot block number", "err", err) + log.Fatal("Failed to encode pivot block number", "err", err) } if err := db.Put(lastPivotKey, enc); err != nil { - log.Crit("Failed to store pivot block number", "err", err) + log.Fatal("Failed to store pivot block number", "err", err) } } @@ -204,7 +204,7 @@ func ReadFastTrieProgress(db ethdb.KeyValueReader) uint64 { // retrieving it across restarts. func WriteFastTrieProgress(db ethdb.KeyValueWriter, count uint64) { if err := db.Put(fastTrieProgressKey, new(big.Int).SetUint64(count).Bytes()); err != nil { - log.Crit("Failed to store fast sync trie progress", "err", err) + log.Fatal("Failed to store fast sync trie progress", "err", err) } } @@ -224,7 +224,7 @@ func ReadTxIndexTail(db ethdb.KeyValueReader) *uint64 { // into database. func WriteTxIndexTail(db ethdb.KeyValueWriter, number uint64) { if err := db.Put(txIndexTailKey, encodeBlockNumber(number)); err != nil { - log.Crit("Failed to store the transaction index tail", "err", err) + log.Fatal("Failed to store the transaction index tail", "err", err) } } @@ -241,7 +241,7 @@ func ReadFastTxLookupLimit(db ethdb.KeyValueReader) *uint64 { // WriteFastTxLookupLimit stores the txlookup limit used in fast sync into database. func WriteFastTxLookupLimit(db ethdb.KeyValueWriter, number uint64) { if err := db.Put(fastTxLookupLimitKey, encodeBlockNumber(number)); err != nil { - log.Crit("Failed to store transaction lookup limit for fast sync", "err", err) + log.Fatal("Failed to store transaction lookup limit for fast sync", "err", err) } } @@ -308,11 +308,11 @@ func WriteHeader(db ethdb.KeyValueWriter, header *types.Header) { // Write the encoded header data, err := rlp.EncodeToBytes(header) if err != nil { - log.Crit("Failed to RLP encode header", "err", err) + log.Fatal("Failed to RLP encode header", "err", err) } key := headerKey(number, hash) if err := db.Put(key, data); err != nil { - log.Crit("Failed to store header", "err", err) + log.Fatal("Failed to store header", "err", err) } } @@ -320,7 +320,7 @@ func WriteHeader(db ethdb.KeyValueWriter, header *types.Header) { func DeleteHeader(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { deleteHeaderWithoutNumber(db, hash, number) if err := db.Delete(headerNumberKey(hash)); err != nil { - log.Crit("Failed to delete hash to number mapping", "err", err) + log.Fatal("Failed to delete hash to number mapping", "err", err) } } @@ -328,7 +328,7 @@ func DeleteHeader(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { // the hash to number mapping. func deleteHeaderWithoutNumber(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { if err := db.Delete(headerKey(number, hash)); err != nil { - log.Crit("Failed to delete header", "err", err) + log.Fatal("Failed to delete header", "err", err) } } @@ -385,7 +385,7 @@ func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64) rlp.RawValue { // WriteBodyRLP stores an RLP encoded block body into the database. func WriteBodyRLP(db ethdb.KeyValueWriter, hash common.Hash, number uint64, rlp rlp.RawValue) { if err := db.Put(blockBodyKey(number, hash), rlp); err != nil { - log.Crit("Failed to store block body", "err", err) + log.Fatal("Failed to store block body", "err", err) } } @@ -418,7 +418,7 @@ func ReadBody(db ethdb.Reader, hash common.Hash, number uint64) *types.Body { func WriteBody(db ethdb.KeyValueWriter, hash common.Hash, number uint64, body *types.Body) { data, err := rlp.EncodeToBytes(body) if err != nil { - log.Crit("Failed to RLP encode body", "err", err) + log.Fatal("Failed to RLP encode body", "err", err) } WriteBodyRLP(db, hash, number, data) } @@ -426,7 +426,7 @@ func WriteBody(db ethdb.KeyValueWriter, hash common.Hash, number uint64, body *t // DeleteBody removes all block body data associated with a hash. func DeleteBody(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { if err := db.Delete(blockBodyKey(number, hash)); err != nil { - log.Crit("Failed to delete block body", "err", err) + log.Fatal("Failed to delete block body", "err", err) } } @@ -452,17 +452,17 @@ func ReadPbCacheBody(db ethdb.Reader, hash common.Hash) *types.Body { func WritePbCacheBody(db ethdb.KeyValueWriter, hash common.Hash, body *types.Body) { data, err := rlp.EncodeToBytes(body) if err != nil { - log.Crit("Failed to RLP encode body", "err", err) + log.Fatal("Failed to RLP encode body", "err", err) } if err := db.Put(pbBodyKey(hash), data); err != nil { - log.Crit("Failed to write pbBodyKey", "err", err) + log.Fatal("Failed to write pbBodyKey", "err", err) } } // DeletePbCacheBody removes all block body data associated with a hash. func DeletePbCacheBody(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Delete(pbBodyKey(hash)); err != nil { - log.Crit("Failed to delete pb cache body", "err", err) + log.Fatal("Failed to delete pb cache body", "err", err) } } @@ -489,10 +489,10 @@ func WritePbBodyKeys(db ethdb.KeyValueWriter, hashes []common.Hash) { key := pbBodyHashKey() data, err := rlp.EncodeToBytes(hashes) if err != nil { - log.Crit("Failed to RLP encode pending block body keys", "err", err) + log.Fatal("Failed to RLP encode pending block body keys", "err", err) } if err := db.Put(key, data); err != nil { - log.Crit("Failed to store pending block body keys", "err", err) + log.Fatal("Failed to store pending block body keys", "err", err) } } @@ -501,7 +501,7 @@ func DeletePbBodyKeys(db ethdb.KeyValueWriter, hash common.Hash) { key := pbBodyHashKey() if err := db.Delete(key); err != nil { - log.Crit("Failed to delete pending block body keys", "err", err) + log.Fatal("Failed to delete pending block body keys", "err", err) } } @@ -525,10 +525,10 @@ func WriteTermini(db ethdb.KeyValueWriter, index common.Hash, hashes []common.Ha key := terminiKey(index) data, err := rlp.EncodeToBytes(hashes) if err != nil { - log.Crit("Failed to RLP encode termini", "err", err) + log.Fatal("Failed to RLP encode termini", "err", err) } if err := db.Put(key, data); err != nil { - log.Crit("Failed to store last block's termini", "err", err) + log.Fatal("Failed to store last block's termini", "err", err) } } @@ -537,7 +537,7 @@ func DeleteTermini(db ethdb.KeyValueWriter, hash common.Hash) { key := terminiKey(hash) if err := db.Delete(key); err != nil { - log.Crit("Failed to delete termini ", "err", err) + log.Fatal("Failed to delete termini ", "err", err) } } @@ -564,11 +564,11 @@ func WritePendingHeader(db ethdb.KeyValueWriter, hash common.Hash, pendingHeader // Write the encoded pending header data, err := rlp.EncodeToBytes(pendingHeader) if err != nil { - log.Crit("Failed to RLP encode pending header", "err", err) + log.Fatal("Failed to RLP encode pending header", "err", err) } if err := db.Put(key, data); err != nil { - log.Crit("Failed to store header", "err", err) + log.Fatal("Failed to store header", "err", err) } } @@ -576,7 +576,7 @@ func WritePendingHeader(db ethdb.KeyValueWriter, hash common.Hash, pendingHeader func DeletePendingHeader(db ethdb.KeyValueWriter, hash common.Hash) { key := pendingHeaderKey(hash) if err := db.Delete(key); err != nil { - log.Crit("Failed to delete slice pending header ", "err", err) + log.Fatal("Failed to delete slice pending header ", "err", err) } } @@ -601,10 +601,10 @@ func WritePhCacheTermini(db ethdb.KeyValueWriter, hash common.Hash, termini []co // Write the encoded pending header data, err := rlp.EncodeToBytes(termini) if err != nil { - log.Crit("Failed to RLP encode pending header", "err", err) + log.Fatal("Failed to RLP encode pending header", "err", err) } if err := db.Put(key, data); err != nil { - log.Crit("Failed to store header", "err", err) + log.Fatal("Failed to store header", "err", err) } } @@ -612,7 +612,7 @@ func WritePhCacheTermini(db ethdb.KeyValueWriter, hash common.Hash, termini []co func DeletePhCacheTermini(db ethdb.KeyValueWriter, hash common.Hash) { key := phBodyTerminiKey(hash) if err := db.Delete(key); err != nil { - log.Crit("Failed to delete slice pending header ", "err", err) + log.Fatal("Failed to delete slice pending header ", "err", err) } } @@ -634,10 +634,10 @@ func ReadPhCacheEntropy(db ethdb.Reader, hash common.Hash) *big.Int { func WritePhCacheEntropy(db ethdb.KeyValueWriter, hash common.Hash, s *big.Int) { data, err := rlp.EncodeToBytes(s) if err != nil { - log.Crit("Failed to RLP encode ph cache entropy", "err", err) + log.Fatal("Failed to RLP encode ph cache entropy", "err", err) } if err := db.Put(phCacheEntropyKey(hash), data); err != nil { - log.Crit("Failed to store ph cache entropy", "err", err) + log.Fatal("Failed to store ph cache entropy", "err", err) } } @@ -677,17 +677,17 @@ func WritePhCache(db ethdb.KeyValueWriter, phCache map[common.Hash]types.Pending data, err := rlp.EncodeToBytes(hashes) if err != nil { - log.Crit("Failed to RLP encode block total difficulty", "err", err) + log.Fatal("Failed to RLP encode block total difficulty", "err", err) } if err := db.Put(phCacheKey, data); err != nil { - log.Crit("Failed to store last block's hash", "err", err) + log.Fatal("Failed to store last block's hash", "err", err) } } // DeletePhCache writes the heads hashes of the blockchain. func DeletePhCache(db ethdb.KeyValueWriter) { if err := db.Delete(phCacheKey); err != nil { - log.Crit("Failed to delete ph cache", "err", err) + log.Fatal("Failed to delete ph cache", "err", err) } } @@ -709,17 +709,17 @@ func ReadBestPhKey(db ethdb.Reader) common.Hash { func WriteBestPhKey(db ethdb.KeyValueWriter, bestPhKey common.Hash) { data, err := rlp.EncodeToBytes(bestPhKey) if err != nil { - log.Crit("Failed to RLP encode write best ph key", "err", err) + log.Fatal("Failed to RLP encode write best ph key", "err", err) } if err := db.Put(phHeadKey, data); err != nil { - log.Crit("Failed to store last block's hash", "err", err) + log.Fatal("Failed to store last block's hash", "err", err) } } // DeleteBestPhKey delete the bestPhKey of the blockchain func DeleteBestPhKey(db ethdb.KeyValueWriter) { if err := db.Delete(phHeadKey); err != nil { - log.Crit("Failed to delete ph head", "err", err) + log.Fatal("Failed to delete ph head", "err", err) } } @@ -740,17 +740,17 @@ func ReadHeadsHashes(db ethdb.Reader) []common.Hash { func WriteHeadsHashes(db ethdb.KeyValueWriter, hashes []common.Hash) { data, err := rlp.EncodeToBytes(hashes) if err != nil { - log.Crit("Failed to RLP encode block total difficulty", "err", err) + log.Fatal("Failed to RLP encode block total difficulty", "err", err) } if err := db.Put(headsHashesKey, data); err != nil { - log.Crit("Failed to store last block's hash", "err", err) + log.Fatal("Failed to store last block's hash", "err", err) } } // DeleteHeadsHashes writes the heads hashes of the blockchain. func DeleteHeadsHashes(db ethdb.KeyValueWriter, hashes []common.Hash) { if err := db.Delete(headsHashesKey); err != nil { - log.Crit("Failed to delete block total difficulty", "err", err) + log.Fatal("Failed to delete block total difficulty", "err", err) } } @@ -853,18 +853,18 @@ func WriteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, rec } bytes, err := rlp.EncodeToBytes(storageReceipts) if err != nil { - log.Crit("Failed to encode block receipts", "err", err) + log.Fatal("Failed to encode block receipts", "err", err) } // Store the flattened receipt slice if err := db.Put(blockReceiptsKey(number, hash), bytes); err != nil { - log.Crit("Failed to store block receipts", "err", err) + log.Fatal("Failed to store block receipts", "err", err) } } // DeleteReceipts removes all receipt data associated with a block hash. func DeleteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { if err := db.Delete(blockReceiptsKey(number, hash)); err != nil { - log.Crit("Failed to delete block receipts", "err", err) + log.Fatal("Failed to delete block receipts", "err", err) } } @@ -1050,7 +1050,7 @@ func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block) { var badBlocks badBlockList if len(blob) > 0 { if err := rlp.DecodeBytes(blob, &badBlocks); err != nil { - log.Crit("Failed to decode old bad blocks", "error", err) + log.Fatal("Failed to decode old bad blocks", "error", err) } } for _, b := range badBlocks { @@ -1069,17 +1069,17 @@ func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block) { } data, err := rlp.EncodeToBytes(badBlocks) if err != nil { - log.Crit("Failed to encode bad blocks", "err", err) + log.Fatal("Failed to encode bad blocks", "err", err) } if err := db.Put(badBlockKey, data); err != nil { - log.Crit("Failed to write bad blocks", "err", err) + log.Fatal("Failed to write bad blocks", "err", err) } } // DeleteBadBlocks deletes all the bad blocks from the database func DeleteBadBlocks(db ethdb.KeyValueWriter) { if err := db.Delete(badBlockKey); err != nil { - log.Crit("Failed to delete bad blocks", "err", err) + log.Fatal("Failed to delete bad blocks", "err", err) } } @@ -1170,7 +1170,7 @@ func ReadEtxSetRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValu // WriteEtxSetRLP stores the EtxSet corresponding to a given block, in RLP encoding. func WriteEtxSetRLP(db ethdb.KeyValueWriter, hash common.Hash, number uint64, rlp rlp.RawValue) { if err := db.Put(etxSetKey(number, hash), rlp); err != nil { - log.Crit("Failed to store etx set", "err", err) + log.Fatal("Failed to store etx set", "err", err) } } @@ -1217,7 +1217,7 @@ func WriteEtxSet(db ethdb.KeyValueWriter, hash common.Hash, number uint64, etxSe } data, err := rlp.EncodeToBytes(entries) if err != nil { - log.Crit("Failed to RLP encode etx set", "err", err) + log.Fatal("Failed to RLP encode etx set", "err", err) } WriteEtxSetRLP(db, hash, number, data) } @@ -1225,7 +1225,7 @@ func WriteEtxSet(db ethdb.KeyValueWriter, hash common.Hash, number uint64, etxSe // DeleteEtxSet removes all EtxSet data associated with a block. func DeleteEtxSet(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { if err := db.Delete(etxSetKey(number, hash)); err != nil { - log.Crit("Failed to delete etx set", "err", err) + log.Fatal("Failed to delete etx set", "err", err) } } @@ -1242,7 +1242,7 @@ func ReadPendingEtxsRLP(db ethdb.Reader, hash common.Hash) rlp.RawValue { // WritePendingEtxsRLP stores the pending ETXs corresponding to a given block, in RLP encoding. func WritePendingEtxsRLP(db ethdb.KeyValueWriter, hash common.Hash, rlp rlp.RawValue) { if err := db.Put(pendingEtxsKey(hash), rlp); err != nil { - log.Crit("Failed to store pending etxs", "err", err) + log.Fatal("Failed to store pending etxs", "err", err) } } @@ -1264,7 +1264,7 @@ func ReadPendingEtxs(db ethdb.Reader, hash common.Hash) *types.PendingEtxs { func WritePendingEtxs(db ethdb.KeyValueWriter, pendingEtxs types.PendingEtxs) { data, err := rlp.EncodeToBytes(pendingEtxs) if err != nil { - log.Crit("Failed to RLP encode pending etxs", "err", err) + log.Fatal("Failed to RLP encode pending etxs", "err", err) } WritePendingEtxsRLP(db, pendingEtxs.Header.Hash(), data) } @@ -1272,7 +1272,7 @@ func WritePendingEtxs(db ethdb.KeyValueWriter, pendingEtxs types.PendingEtxs) { // DeletePendingEtxs removes all pending ETX data associated with a block. func DeletePendingEtxs(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { if err := db.Delete(pendingEtxsKey(hash)); err != nil { - log.Crit("Failed to delete pending etxs", "err", err) + log.Fatal("Failed to delete pending etxs", "err", err) } } @@ -1295,16 +1295,16 @@ func ReadPendingEtxsRollup(db ethdb.Reader, hash common.Hash) *types.PendingEtxs func WritePendingEtxsRollup(db ethdb.KeyValueWriter, pendingEtxsRollup types.PendingEtxsRollup) { data, err := rlp.EncodeToBytes(pendingEtxsRollup) if err != nil { - log.Crit("Failed to RLP encode pending etxs rollup", "err", err) + log.Fatal("Failed to RLP encode pending etxs rollup", "err", err) } if err := db.Put(pendingEtxsRollupKey(pendingEtxsRollup.Header.Hash()), data); err != nil { - log.Crit("Failed to store pending etxs rollup", "err", err) + log.Fatal("Failed to store pending etxs rollup", "err", err) } } // DeletePendingEtxsRollup removes all pending ETX rollup data associated with a block. func DeletePendingEtxsRollup(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Delete(pendingEtxsRollupKey(hash)); err != nil { - log.Crit("Failed to delete pending etxs rollup", "err", err) + log.Fatal("Failed to delete pending etxs rollup", "err", err) } } diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index a0d1c608f0..57d93bcea0 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -57,7 +57,7 @@ func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) *uint64 { // enabling hash based transaction and receipt lookups. func writeTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash, numberBytes []byte) { if err := db.Put(txLookupKey(hash), numberBytes); err != nil { - log.Crit("Failed to store transaction lookup entry", "err", err) + log.Fatal("Failed to store transaction lookup entry", "err", err) } } @@ -82,7 +82,7 @@ func WriteTxLookupEntriesByBlock(db ethdb.KeyValueWriter, block *types.Block) { // DeleteTxLookupEntry removes all transaction data associated with a hash. func DeleteTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Delete(txLookupKey(hash)); err != nil { - log.Crit("Failed to delete transaction lookup entry", "err", err) + log.Fatal("Failed to delete transaction lookup entry", "err", err) } } @@ -151,7 +151,7 @@ func ReadBloomBits(db ethdb.KeyValueReader, bit uint, section uint64, head commo // section and bit index. func WriteBloomBits(db ethdb.KeyValueWriter, bit uint, section uint64, head common.Hash, bits []byte) { if err := db.Put(bloomBitsKey(bit, section, head), bits); err != nil { - log.Crit("Failed to store bloom bits", "err", err) + log.Fatal("Failed to store bloom bits", "err", err) } } @@ -172,6 +172,6 @@ func DeleteBloombits(db ethdb.Database, bit uint, from uint64, to uint64) { db.Delete(it.Key()) } if it.Error() != nil { - log.Crit("Failed to delete bloom bits", "err", it.Error()) + log.Fatal("Failed to delete bloom bits", "err", it.Error()) } } diff --git a/core/rawdb/accessors_metadata.go b/core/rawdb/accessors_metadata.go index 103d484698..978502b42b 100644 --- a/core/rawdb/accessors_metadata.go +++ b/core/rawdb/accessors_metadata.go @@ -46,10 +46,10 @@ func ReadDatabaseVersion(db ethdb.KeyValueReader) *uint64 { func WriteDatabaseVersion(db ethdb.KeyValueWriter, version uint64) { enc, err := rlp.EncodeToBytes(version) if err != nil { - log.Crit("Failed to encode database version", "err", err) + log.Fatal("Failed to encode database version", "err", err) } if err = db.Put(databaseVersionKey, enc); err != nil { - log.Crit("Failed to store the database version", "err", err) + log.Fatal("Failed to store the database version", "err", err) } } @@ -74,10 +74,10 @@ func WriteChainConfig(db ethdb.KeyValueWriter, hash common.Hash, cfg *params.Cha } data, err := json.Marshal(cfg) if err != nil { - log.Crit("Failed to JSON encode chain config", "err", err) + log.Fatal("Failed to JSON encode chain config", "err", err) } if err := db.Put(configKey(hash), data); err != nil { - log.Crit("Failed to store chain config", "err", err) + log.Fatal("Failed to store chain config", "err", err) } } diff --git a/core/rawdb/accessors_snapshot.go b/core/rawdb/accessors_snapshot.go index 5862e1e9c5..ee91b679ee 100644 --- a/core/rawdb/accessors_snapshot.go +++ b/core/rawdb/accessors_snapshot.go @@ -33,14 +33,14 @@ func ReadSnapshotDisabled(db ethdb.KeyValueReader) bool { // WriteSnapshotDisabled stores the snapshot pause flag. func WriteSnapshotDisabled(db ethdb.KeyValueWriter) { if err := db.Put(snapshotDisabledKey, []byte("42")); err != nil { - log.Crit("Failed to store snapshot disabled flag", "err", err) + log.Fatal("Failed to store snapshot disabled flag", "err", err) } } // DeleteSnapshotDisabled deletes the flag keeping the snapshot maintenance disabled. func DeleteSnapshotDisabled(db ethdb.KeyValueWriter) { if err := db.Delete(snapshotDisabledKey); err != nil { - log.Crit("Failed to remove snapshot disabled flag", "err", err) + log.Fatal("Failed to remove snapshot disabled flag", "err", err) } } @@ -58,7 +58,7 @@ func ReadSnapshotRoot(db ethdb.KeyValueReader) common.Hash { // the persisted snapshot. func WriteSnapshotRoot(db ethdb.KeyValueWriter, root common.Hash) { if err := db.Put(snapshotRootKey, root[:]); err != nil { - log.Crit("Failed to store snapshot root", "err", err) + log.Fatal("Failed to store snapshot root", "err", err) } } @@ -68,7 +68,7 @@ func WriteSnapshotRoot(db ethdb.KeyValueWriter, root common.Hash) { // invalid. func DeleteSnapshotRoot(db ethdb.KeyValueWriter) { if err := db.Delete(snapshotRootKey); err != nil { - log.Crit("Failed to remove snapshot root", "err", err) + log.Fatal("Failed to remove snapshot root", "err", err) } } @@ -81,14 +81,14 @@ func ReadAccountSnapshot(db ethdb.KeyValueReader, hash common.Hash) []byte { // WriteAccountSnapshot stores the snapshot entry of an account trie leaf. func WriteAccountSnapshot(db ethdb.KeyValueWriter, hash common.Hash, entry []byte) { if err := db.Put(accountSnapshotKey(hash), entry); err != nil { - log.Crit("Failed to store account snapshot", "err", err) + log.Fatal("Failed to store account snapshot", "err", err) } } // DeleteAccountSnapshot removes the snapshot entry of an account trie leaf. func DeleteAccountSnapshot(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Delete(accountSnapshotKey(hash)); err != nil { - log.Crit("Failed to delete account snapshot", "err", err) + log.Fatal("Failed to delete account snapshot", "err", err) } } @@ -101,14 +101,14 @@ func ReadStorageSnapshot(db ethdb.KeyValueReader, accountHash, storageHash commo // WriteStorageSnapshot stores the snapshot entry of an storage trie leaf. func WriteStorageSnapshot(db ethdb.KeyValueWriter, accountHash, storageHash common.Hash, entry []byte) { if err := db.Put(storageSnapshotKey(accountHash, storageHash), entry); err != nil { - log.Crit("Failed to store storage snapshot", "err", err) + log.Fatal("Failed to store storage snapshot", "err", err) } } // DeleteStorageSnapshot removes the snapshot entry of an storage trie leaf. func DeleteStorageSnapshot(db ethdb.KeyValueWriter, accountHash, storageHash common.Hash) { if err := db.Delete(storageSnapshotKey(accountHash, storageHash)); err != nil { - log.Crit("Failed to delete storage snapshot", "err", err) + log.Fatal("Failed to delete storage snapshot", "err", err) } } @@ -129,7 +129,7 @@ func ReadSnapshotJournal(db ethdb.KeyValueReader) []byte { // shutdown. The blob is expected to be max a few 10s of megabytes. func WriteSnapshotJournal(db ethdb.KeyValueWriter, journal []byte) { if err := db.Put(snapshotJournalKey, journal); err != nil { - log.Crit("Failed to store snapshot journal", "err", err) + log.Fatal("Failed to store snapshot journal", "err", err) } } @@ -137,7 +137,7 @@ func WriteSnapshotJournal(db ethdb.KeyValueWriter, journal []byte) { // the last shutdown func DeleteSnapshotJournal(db ethdb.KeyValueWriter) { if err := db.Delete(snapshotJournalKey); err != nil { - log.Crit("Failed to remove snapshot journal", "err", err) + log.Fatal("Failed to remove snapshot journal", "err", err) } } @@ -152,7 +152,7 @@ func ReadSnapshotGenerator(db ethdb.KeyValueReader) []byte { // shutdown. func WriteSnapshotGenerator(db ethdb.KeyValueWriter, generator []byte) { if err := db.Put(snapshotGeneratorKey, generator); err != nil { - log.Crit("Failed to store snapshot generator", "err", err) + log.Fatal("Failed to store snapshot generator", "err", err) } } @@ -160,7 +160,7 @@ func WriteSnapshotGenerator(db ethdb.KeyValueWriter, generator []byte) { // the last shutdown func DeleteSnapshotGenerator(db ethdb.KeyValueWriter) { if err := db.Delete(snapshotGeneratorKey); err != nil { - log.Crit("Failed to remove snapshot generator", "err", err) + log.Fatal("Failed to remove snapshot generator", "err", err) } } @@ -184,7 +184,7 @@ func WriteSnapshotRecoveryNumber(db ethdb.KeyValueWriter, number uint64) { var buf [8]byte binary.BigEndian.PutUint64(buf[:], number) if err := db.Put(snapshotRecoveryKey, buf[:]); err != nil { - log.Crit("Failed to store snapshot recovery number", "err", err) + log.Fatal("Failed to store snapshot recovery number", "err", err) } } @@ -192,7 +192,7 @@ func WriteSnapshotRecoveryNumber(db ethdb.KeyValueWriter, number uint64) { // snapshot layer. func DeleteSnapshotRecoveryNumber(db ethdb.KeyValueWriter) { if err := db.Delete(snapshotRecoveryKey); err != nil { - log.Crit("Failed to remove snapshot recovery number", "err", err) + log.Fatal("Failed to remove snapshot recovery number", "err", err) } } @@ -205,7 +205,7 @@ func ReadSnapshotSyncStatus(db ethdb.KeyValueReader) []byte { // WriteSnapshotSyncStatus stores the serialized sync status to save at shutdown. func WriteSnapshotSyncStatus(db ethdb.KeyValueWriter, status []byte) { if err := db.Put(snapshotSyncStatusKey, status); err != nil { - log.Crit("Failed to store snapshot sync status", "err", err) + log.Fatal("Failed to store snapshot sync status", "err", err) } } @@ -213,6 +213,6 @@ func WriteSnapshotSyncStatus(db ethdb.KeyValueWriter, status []byte) { // shutdown func DeleteSnapshotSyncStatus(db ethdb.KeyValueWriter) { if err := db.Delete(snapshotSyncStatusKey); err != nil { - log.Crit("Failed to remove snapshot sync status", "err", err) + log.Fatal("Failed to remove snapshot sync status", "err", err) } } diff --git a/core/rawdb/accessors_state.go b/core/rawdb/accessors_state.go index d3a04a6ee0..19f71172e3 100644 --- a/core/rawdb/accessors_state.go +++ b/core/rawdb/accessors_state.go @@ -32,7 +32,7 @@ func ReadPreimage(db ethdb.KeyValueReader, hash common.Hash) []byte { func WritePreimages(db ethdb.KeyValueWriter, preimages map[common.Hash][]byte) { for hash, preimage := range preimages { if err := db.Put(preimageKey(hash), preimage); err != nil { - log.Crit("Failed to store trie preimage", "err", err) + log.Fatal("Failed to store trie preimage", "err", err) } } preimageCounter.Inc(int64(len(preimages))) @@ -64,14 +64,14 @@ func ReadCodeWithPrefix(db ethdb.KeyValueReader, hash common.Hash) []byte { // WriteCode writes the provided contract code database. func WriteCode(db ethdb.KeyValueWriter, hash common.Hash, code []byte) { if err := db.Put(codeKey(hash), code); err != nil { - log.Crit("Failed to store contract code", "err", err) + log.Fatal("Failed to store contract code", "err", err) } } // DeleteCode deletes the specified contract code from the database. func DeleteCode(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Delete(codeKey(hash)); err != nil { - log.Crit("Failed to delete contract code", "err", err) + log.Fatal("Failed to delete contract code", "err", err) } } @@ -84,13 +84,13 @@ func ReadTrieNode(db ethdb.KeyValueReader, hash common.Hash) []byte { // WriteTrieNode writes the provided trie node database. func WriteTrieNode(db ethdb.KeyValueWriter, hash common.Hash, node []byte) { if err := db.Put(hash.Bytes(), node); err != nil { - log.Crit("Failed to store trie node", "err", err) + log.Fatal("Failed to store trie node", "err", err) } } // DeleteTrieNode deletes the specified trie node from the database. func DeleteTrieNode(db ethdb.KeyValueWriter, hash common.Hash) { if err := db.Delete(hash.Bytes()); err != nil { - log.Crit("Failed to delete trie node", "err", err) + log.Fatal("Failed to delete trie node", "err", err) } } diff --git a/core/rawdb/chain_iterator.go b/core/rawdb/chain_iterator.go index 2bfcf9bad2..76c1ef1892 100644 --- a/core/rawdb/chain_iterator.go +++ b/core/rawdb/chain_iterator.go @@ -50,7 +50,7 @@ func InitDatabaseFromFreezer(db ethdb.Database) { // freezerdb return N items (e.g up to 1000 items per go) // That would require an API change in Ancients though if h, err := db.Ancient(freezerHashTable, i); err != nil { - log.Crit("Failed to init database from freezer", "err", err) + log.Fatal("Failed to init database from freezer", "err", err) } else { hash = common.BytesToHash(h) } @@ -58,7 +58,7 @@ func InitDatabaseFromFreezer(db ethdb.Database) { // If enough data was accumulated in memory or we're at the last block, dump to disk if batch.ValueSize() > ethdb.IdealBatchSize { if err := batch.Write(); err != nil { - log.Crit("Failed to write data to db", "err", err) + log.Fatal("Failed to write data to db", "err", err) } batch.Reset() } @@ -69,7 +69,7 @@ func InitDatabaseFromFreezer(db ethdb.Database) { } } if err := batch.Write(); err != nil { - log.Crit("Failed to write data to db", "err", err) + log.Fatal("Failed to write data to db", "err", err) } batch.Reset() @@ -213,7 +213,7 @@ func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan if batch.ValueSize() > ethdb.IdealBatchSize { WriteTxIndexTail(batch, lastNum) // Also write the tail here if err := batch.Write(); err != nil { - log.Crit("Failed writing batch to db", "error", err) + log.Fatal("Failed writing batch to db", "error", err) return } batch.Reset() @@ -230,7 +230,7 @@ func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan // be flushed anyway. WriteTxIndexTail(batch, lastNum) if err := batch.Write(); err != nil { - log.Crit("Failed writing batch to db", "error", err) + log.Fatal("Failed writing batch to db", "error", err) return } select { @@ -304,7 +304,7 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch if blocks%1000 == 0 { WriteTxIndexTail(batch, nextNum) if err := batch.Write(); err != nil { - log.Crit("Failed writing batch to db", "error", err) + log.Fatal("Failed writing batch to db", "error", err) return } batch.Reset() @@ -321,7 +321,7 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch // be flushed anyway. WriteTxIndexTail(batch, nextNum) if err := batch.Write(); err != nil { - log.Crit("Failed writing batch to db", "error", err) + log.Fatal("Failed writing batch to db", "error", err) return } select { diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go index 81143715d4..e00561d7e8 100644 --- a/core/rawdb/freezer.go +++ b/core/rawdb/freezer.go @@ -213,7 +213,7 @@ func (f *freezer) AppendAncient(number uint64, hash, header, body, receipts, etx if err != nil { rerr := f.repair() if rerr != nil { - log.Crit("Failed to repair freezer", "err", rerr) + log.Fatal("Failed to repair freezer", "err", rerr) } log.Info("Append ancient failed", "number", number, "err", err) } @@ -386,7 +386,7 @@ func (f *freezer) freeze(db ethdb.KeyValueStore) { } // Batch of blocks have been frozen, flush them before wiping from leveldb if err := f.Sync(); err != nil { - log.Crit("Failed to flush frozen tables", "err", err) + log.Fatal("Failed to flush frozen tables", "err", err) } // Wipe out all data from the active database batch := db.NewBatch() @@ -398,7 +398,7 @@ func (f *freezer) freeze(db ethdb.KeyValueStore) { } } if err := batch.Write(); err != nil { - log.Crit("Failed to delete frozen canonical blocks", "err", err) + log.Fatal("Failed to delete frozen canonical blocks", "err", err) } batch.Reset() @@ -415,7 +415,7 @@ func (f *freezer) freeze(db ethdb.KeyValueStore) { } } if err := batch.Write(); err != nil { - log.Crit("Failed to delete frozen side blocks", "err", err) + log.Fatal("Failed to delete frozen side blocks", "err", err) } batch.Reset() @@ -449,7 +449,7 @@ func (f *freezer) freeze(db ethdb.KeyValueStore) { tip++ } if err := batch.Write(); err != nil { - log.Crit("Failed to delete dangling side blocks", "err", err) + log.Fatal("Failed to delete dangling side blocks", "err", err) } } // Log something friendly for the user diff --git a/core/rawdb/freezer_table.go b/core/rawdb/freezer_table.go index 9f1a08e4d7..76407e292a 100644 --- a/core/rawdb/freezer_table.go +++ b/core/rawdb/freezer_table.go @@ -180,7 +180,7 @@ func newCustomTable(path string, name string, readMeter metrics.Meter, writeMete sizeGauge: sizeGauge, name: name, path: path, - logger: log.New("database", path, "table", name), + logger: log.Log, noCompression: noCompression, maxFileSize: maxFilesize, } diff --git a/core/slice.go b/core/slice.go index 3858220da2..d1661beda8 100644 --- a/core/slice.go +++ b/core/slice.go @@ -768,11 +768,11 @@ func (sl *Slice) SubscribeMissingParentEvent(ch chan<- common.Hash) event.Subscr // MakeDomClient creates the quaiclient for the given domurl func makeDomClient(domurl string) *quaiclient.Client { if domurl == "" { - log.Crit("dom client url is empty") + log.Fatal("dom client url is empty") } domClient, err := quaiclient.Dial(domurl) if err != nil { - log.Crit("Error connecting to the dominant go-quai client", "err", err) + log.Fatal("Error connecting to the dominant go-quai client", "err", err) } return domClient } @@ -784,7 +784,7 @@ func makeSubClients(suburls []string) []*quaiclient.Client { if suburl != "" { subClient, err := quaiclient.Dial(suburl) if err != nil { - log.Crit("Error connecting to the subordinate go-quai client for index", "index", i, " err ", err) + log.Fatal("Error connecting to the subordinate go-quai client for index", "index", i, " err ", err) } subClients[i] = subClient } diff --git a/core/state/snapshot/generate.go b/core/state/snapshot/generate.go index 79a47827ab..550d492116 100644 --- a/core/state/snapshot/generate.go +++ b/core/state/snapshot/generate.go @@ -154,7 +154,7 @@ func generateSnapshot(diskdb ethdb.KeyValueStore, triedb *trie.Database, cache i rawdb.WriteSnapshotRoot(batch, root) journalProgress(batch, genMarker, stats) if err := batch.Write(); err != nil { - log.Crit("Failed to write initialized state marker", "err", err) + log.Fatal("Failed to write initialized state marker", "err", err) } base := &diskLayer{ diskdb: diskdb, @@ -394,7 +394,7 @@ func (dl *diskLayer) generateRange(root common.Hash, prefix []byte, kind string, if len(origin) > 0 { logCtx = append(logCtx, "origin", hexutil.Encode(origin)) } - logger := log.New(logCtx...) + logger := log.Log // The range prover says the range is correct, skip trie iteration if result.valid() { @@ -612,7 +612,7 @@ func (dl *diskLayer) generate(stats *generatorStats) { CodeHash []byte } if err := rlp.DecodeBytes(val, &acc); err != nil { - log.Crit("Invalid account encountered during snapshot creation", "err", err) + log.Fatal("Invalid account encountered during snapshot creation", "err", err) } // If the account is not yet in-progress, write it out if accMarker == nil || !bytes.Equal(accountHash[:], accMarker) { diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index 4382168580..d484200958 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -279,7 +279,7 @@ func (t *Tree) Disable() { // Note, we don't delete the sync progress if err := batch.Write(); err != nil { - log.Crit("Failed to disable snapshots", "err", err) + log.Fatal("Failed to disable snapshots", "err", err) } } @@ -542,7 +542,7 @@ func diffToDisk(bottom *diffLayer) *diskLayer { // crash and we'll detect and regenerate the snapshot. if batch.ValueSize() > ethdb.IdealBatchSize { if err := batch.Write(); err != nil { - log.Crit("Failed to write storage deletions", "err", err) + log.Fatal("Failed to write storage deletions", "err", err) } batch.Reset() } @@ -569,7 +569,7 @@ func diffToDisk(bottom *diffLayer) *diskLayer { // the snapshot. if batch.ValueSize() > ethdb.IdealBatchSize { if err := batch.Write(); err != nil { - log.Crit("Failed to write storage deletions", "err", err) + log.Fatal("Failed to write storage deletions", "err", err) } batch.Reset() } @@ -609,7 +609,7 @@ func diffToDisk(bottom *diffLayer) *diskLayer { // Flush all the updates in the single db operation. Ensure the // disk layer transition is atomic. if err := batch.Write(); err != nil { - log.Crit("Failed to write leftover snapshot", "err", err) + log.Fatal("Failed to write leftover snapshot", "err", err) } log.Debug("Journalled disk layer", "root", bottom.root, "complete", base.genMarker == nil) res := &diskLayer{ diff --git a/core/state/statedb.go b/core/state/statedb.go index fdfa93e23a..ec9fabd1a2 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -922,7 +922,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { } if codeWriter.ValueSize() > 0 { if err := codeWriter.Write(); err != nil { - log.Crit("Failed to commit dirty codes", "error", err) + log.Fatal("Failed to commit dirty codes", "error", err) } } // Write the account trie changes, measuing the amount of wasted time diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 2f17878627..814470d80f 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -213,13 +213,7 @@ func (d *Downloader) Synchronising() bool { // RegisterPeer injects a new download peer into the set of block source to be // used for fetching hashes and blocks from. func (d *Downloader) RegisterPeer(id string, version uint, peer Peer) error { - var logger log.Logger - if len(id) < 16 { - // Tests use short IDs, don't choke on them - logger = log.New("peer", id) - } else { - logger = log.New("peer", id[:8]) - } + logger := log.Log logger.Trace("Registering sync peer") if err := d.peers.Register(newPeerConnection(id, version, peer, logger)); err != nil { logger.Error("Failed to register sync peer", "err", err) @@ -238,13 +232,7 @@ func (d *Downloader) HeadEntropy() *big.Int { // the queue. func (d *Downloader) UnregisterPeer(id string) error { // Unregister the peer from the active peer set and revoke any fetch tasks - var logger log.Logger - if len(id) < 16 { - // Tests use short IDs, don't choke on them - logger = log.New("peer", id) - } else { - logger = log.New("peer", id[:8]) - } + logger := log.Log logger.Trace("Unregistering sync peer") if err := d.peers.Unregister(id); err != nil { logger.Error("Failed to unregister sync peer", "err", err) diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go index fd8e0ce129..39880251b9 100644 --- a/eth/downloader/peer.go +++ b/eth/downloader/peer.go @@ -296,7 +296,7 @@ type peerSet struct { func newPeerSet() *peerSet { return &peerSet{ peers: make(map[string]*peerConnection), - rates: msgrate.NewTrackers(log.New("proto", "eth")), + rates: msgrate.NewTrackers(log.Log), } } diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 7df3e90c46..2e61f3fba1 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -696,9 +696,9 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh var logger log.Logger if len(id) < 16 { // Tests use short IDs, don't choke on them - logger = log.New("peer", id) + logger = log.Log } else { - logger = log.New("peer", id[:16]) + logger = log.Log } // Short circuit if the data was never requested request := q.headerPendPool[id] diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 0f0a0c50fb..4385fae26e 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -143,11 +143,11 @@ func NewEventSystem(backend Backend, lightMode bool) *EventSystem { // Make sure none of the subscriptions are empty if nodeCtx == common.ZONE_CTX { if m.txsSub == nil || m.logsSub == nil || m.rmLogsSub == nil || m.chainSub == nil || m.pendingLogsSub == nil || m.pendingHeaderSub == nil { - log.Crit("Subscribe for event system failed") + log.Fatal("Subscribe for event system failed") } } else { if m.chainSub == nil { - log.Crit("Subscribe for event system failed") + log.Fatal("Subscribe for event system failed") } } diff --git a/eth/handler.go b/eth/handler.go index b922115275..66d0875881 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -291,9 +291,9 @@ func (h *handler) unregisterPeer(id string) { var logger log.Logger if len(id) < 16 { // Tests use short IDs, don't choke on them - logger = log.New("peer", id) + logger = log.Log } else { - logger = log.New("peer", id[:8]) + logger = log.Log } // Abort if the peer does not exist peer := h.peers.peer(id) diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index e2590f26e8..2609dd54b2 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -108,13 +108,14 @@ func New(file string, cache int, handles int, namespace string, readonly bool) ( // The customize function allows the caller to modify the leveldb options. func NewCustom(file string, namespace string, customize func(options *opt.Options)) (*Database, error) { options := configureOptions(customize) - logger := log.New("database", file) + logger := log.Log usedCache := options.GetBlockCacheCapacity() + options.GetWriteBuffer()*2 logCtx := []interface{}{"cache", common.StorageSize(usedCache), "handles", options.GetOpenFilesCacheCapacity()} if options.ReadOnly { logCtx = append(logCtx, "readonly", "true") } - logger.Info("Allocated cache and file handles", logCtx...) + logger.Info("Allocated cache and file handles") + logger.Info(logCtx...) // Open the db and recover any potential corruptions db, err := leveldb.OpenFile(file, options) diff --git a/go.mod b/go.mod index 39008e4f6c..cb7b30703f 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf github.com/dominant-strategies/bn256 v0.0.0-20220930122411-fbf930a7493d github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 - github.com/go-stack/stack v1.8.0 github.com/golang/snappy v0.0.3 github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa github.com/gorilla/websocket v1.4.2 @@ -24,14 +23,15 @@ require ( github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e github.com/ledgerwatch/secp256k1 v1.0.0 - github.com/mattn/go-colorable v0.1.0 - github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 + github.com/natefinch/lumberjack v2.0.0+incompatible github.com/olekukonko/tablewriter v0.0.5 github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 github.com/prometheus/tsdb v0.7.1 github.com/rs/cors v1.7.0 + github.com/sasha-s/go-deadlock v0.3.1 github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible + github.com/sirupsen/logrus v1.9.0 github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa @@ -59,11 +59,11 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect - github.com/sasha-s/go-deadlock v0.3.1 // indirect github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tklauser/numcpus v0.2.2 // indirect golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect golang.org/x/text v0.3.6 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect gotest.tools v2.2.0+incompatible // indirect ) diff --git a/go.sum b/go.sum index 039c6a3882..e4b31be2a8 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,7 @@ github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1Gn github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= @@ -114,7 +115,6 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -221,14 +221,10 @@ github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf github.com/ledgerwatch/secp256k1 v1.0.0/go.mod h1:SPmqJFciiF/Q0mPt2jVs2dTr/1TZBTIA+kPMmKgBAak= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o= -github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d h1:oNAwILwmgWKFpuU+dXvI6dl9jG2mAWAZLX3r9s0PPiw= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 h1:USWjF42jDCSEeikX/G1g40ZWnsPXN5WkZ4jMHZWyBK4= -github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -243,6 +239,8 @@ github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hz github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 h1:shk/vn9oCoOTmwcouEdwIeOtOGA/ELRUw/GwvxwfT+0= github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= +github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= +github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= @@ -300,6 +298,8 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -425,6 +425,7 @@ golang.org/x/sys v0.0.0-20200806125547-5acd03effb82/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80= golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -516,6 +517,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= diff --git a/internal/debug/api.go b/internal/debug/api.go index 4451b59d7d..f26a564e21 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -31,9 +31,10 @@ import ( "runtime/debug" "runtime/pprof" "strings" - sync "github.com/sasha-s/go-deadlock" "time" + sync "github.com/sasha-s/go-deadlock" + "github.com/dominant-strategies/go-quai/log" ) @@ -54,19 +55,7 @@ type HandlerT struct { // Verbosity sets the log verbosity ceiling. The verbosity of individual packages // and source files can be raised using Vmodule. func (*HandlerT) Verbosity(level int) { - glogger.Verbosity(log.Lvl(level)) -} - -// Vmodule sets the log verbosity pattern. See package log for details on the -// pattern syntax. -func (*HandlerT) Vmodule(pattern string) error { - return glogger.Vmodule(pattern) -} - -// BacktraceAt sets the log backtrace location. See package log for details on -// the pattern syntax. -func (*HandlerT) BacktraceAt(location string) error { - return glogger.BacktraceAt(location) + log.SetLevelInt(level) } // MemStats returns detailed runtime memory statistics. diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 0d6082f3d1..919e797e25 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -18,18 +18,14 @@ package debug import ( "fmt" - "io" "net/http" _ "net/http/pprof" - "os" "runtime" "github.com/dominant-strategies/go-quai/log" "github.com/dominant-strategies/go-quai/metrics" "github.com/dominant-strategies/go-quai/metrics/exp" "github.com/fjl/memsize/memsizeui" - "github.com/mattn/go-colorable" - "github.com/mattn/go-isatty" "gopkg.in/urfave/cli.v1" ) @@ -152,57 +148,12 @@ var DeprecatedFlags = []cli.Flag{ legacyDebugFlag, } -var glogger *log.GlogHandler - func init() { - glogger = log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false))) - glogger.Verbosity(log.LvlInfo) - log.Root().SetHandler(glogger) } // Setup initializes profiling and logging based on the CLI flags. // It should be called as early as possible in the program. func Setup(ctx *cli.Context) error { - var ostream log.Handler - output := io.Writer(os.Stderr) - if ctx.GlobalBool(logjsonFlag.Name) { - ostream = log.StreamHandler(output, log.JSONFormat()) - } else { - usecolor := (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) && os.Getenv("TERM") != "dumb" - if usecolor { - output = colorable.NewColorableStderr() - } - ostream = log.StreamHandler(output, log.TerminalFormat(usecolor)) - } - glogger.SetHandler(ostream) - - // logging - verbosity := ctx.GlobalInt(verbosityFlag.Name) - glogger.Verbosity(log.Lvl(verbosity)) - vmodule := ctx.GlobalString(vmoduleFlag.Name) - glogger.Vmodule(vmodule) - - debug := ctx.GlobalBool(debugFlag.Name) - if ctx.GlobalIsSet(legacyDebugFlag.Name) { - debug = ctx.GlobalBool(legacyDebugFlag.Name) - log.Warn("The flag --debug is deprecated and will be removed in the future, please use --log.debug") - } - if ctx.GlobalIsSet(debugFlag.Name) { - debug = ctx.GlobalBool(debugFlag.Name) - } - log.PrintOrigins(debug) - - backtrace := ctx.GlobalString(backtraceAtFlag.Name) - if b := ctx.GlobalString(legacyBacktraceAtFlag.Name); b != "" { - backtrace = b - log.Warn("The flag --backtrace is deprecated and will be removed in the future, please use --log.backtrace") - } - if b := ctx.GlobalString(backtraceAtFlag.Name); b != "" { - backtrace = b - } - glogger.BacktraceAt(backtrace) - - log.Root().SetHandler(glogger) // profiling, tracing runtime.MemProfileRate = memprofilerateFlag.Value diff --git a/internal/testlog/testlog.go b/internal/testlog/testlog.go index c84c019d40..13cbf30702 100644 --- a/internal/testlog/testlog.go +++ b/internal/testlog/testlog.go @@ -116,7 +116,7 @@ func (l *logger) Crit(msg string, ctx ...interface{}) { l.t.Helper() l.mu.Lock() defer l.mu.Unlock() - l.l.Crit(msg, ctx...) + l.l.Fatal(msg, ctx...) l.flush() } diff --git a/node/config.go b/node/config.go index ccf7eb047d..cc2f75558a 100644 --- a/node/config.go +++ b/node/config.go @@ -290,7 +290,7 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey { if c.DataDir == "" { key, err := crypto.GenerateKey() if err != nil { - log.Crit(fmt.Sprintf("Failed to generate ephemeral node key: %v", err)) + log.Fatal(fmt.Sprintf("Failed to generate ephemeral node key: %v", err)) } return key } @@ -302,7 +302,7 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey { // No persistent key found, generate and store a new one. key, err := crypto.GenerateKey() if err != nil { - log.Crit(fmt.Sprintf("Failed to generate node key: %v", err)) + log.Fatal(fmt.Sprintf("Failed to generate node key: %v", err)) } instanceDir := filepath.Join(c.DataDir, c.name()) if err := os.MkdirAll(instanceDir, 0700); err != nil { @@ -371,7 +371,7 @@ func (c *Config) warnOnce(w *bool, format string, args ...interface{}) { } l := c.Logger if l == nil { - l = log.Root() + l = log.Log } l.Warn(fmt.Sprintf(format, args...)) *w = true diff --git a/node/node.go b/node/node.go index 97240bfa7a..0fd9693ccb 100644 --- a/node/node.go +++ b/node/node.go @@ -76,7 +76,7 @@ func New(conf *Config) (*Node, error) { conf.DataDir = absdatadir } if conf.Logger == nil { - conf.Logger = log.New() + conf.Logger = log.Log } // Ensure that the instance name doesn't cause weird conflicts with diff --git a/p2p/dial.go b/p2p/dial.go index f39b5ce4ab..852e8bd699 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -145,7 +145,7 @@ func (cfg dialConfig) withDefaults() dialConfig { cfg.maxActiveDials = defaultMaxPendingPeers } if cfg.log == nil { - cfg.log = log.Root() + cfg.log = log.Log } if cfg.clock == nil { cfg.clock = mclock.System{} diff --git a/p2p/discover/common.go b/p2p/discover/common.go index 74e5f005b6..0f7e6cd395 100644 --- a/p2p/discover/common.go +++ b/p2p/discover/common.go @@ -25,6 +25,7 @@ import ( "github.com/dominant-strategies/go-quai/p2p/enode" "github.com/dominant-strategies/go-quai/p2p/enr" "github.com/dominant-strategies/go-quai/p2p/netutil" + "github.com/sirupsen/logrus" ) // UDPConn is a network connection on which discovery can operate. @@ -44,14 +45,14 @@ type Config struct { NetRestrict *netutil.Netlist // list of allowed IP networks Bootnodes []*enode.Node // list of bootstrap nodes Unhandled chan<- ReadPacket // unhandled packets are sent on this channel - Log log.Logger // if set, log messages go here + Log *logrus.Logger // if set, log messages go here ValidSchemes enr.IdentityScheme // allowed identity schemes Clock mclock.Clock } func (cfg Config) withDefaults() Config { if cfg.Log == nil { - cfg.Log = log.Root() + cfg.Log = log.Log } if cfg.ValidSchemes == nil { cfg.ValidSchemes = enode.ValidSchemes diff --git a/p2p/discover/table.go b/p2p/discover/table.go index f05d8b0509..b41512e85a 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -305,8 +305,7 @@ func (tab *Table) loadSeedNodes() { seeds = append(seeds, tab.nursery...) for i := range seeds { seed := seeds[i] - age := log.Lazy{Fn: func() interface{} { return time.Since(tab.db.LastPongReceived(seed.ID(), seed.IP())) }} - tab.log.Trace("Found seed node in database", "id", seed.ID(), "addr", seed.addr(), "age", age) + tab.log.Trace("Found seed node in database", "id", seed.ID(), "addr", seed.addr()) tab.addSeenNode(seed) } } diff --git a/p2p/discover/v4_udp.go b/p2p/discover/v4_udp.go index 42f824571f..018d2f21bf 100644 --- a/p2p/discover/v4_udp.go +++ b/p2p/discover/v4_udp.go @@ -30,10 +30,10 @@ import ( "time" "github.com/dominant-strategies/go-quai/crypto" - "github.com/dominant-strategies/go-quai/log" "github.com/dominant-strategies/go-quai/p2p/discover/v4wire" "github.com/dominant-strategies/go-quai/p2p/enode" "github.com/dominant-strategies/go-quai/p2p/netutil" + "github.com/dominant-strategies/go-quai/log" ) // Errors @@ -140,7 +140,7 @@ func ListenV4(c UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv4, error) { addReplyMatcher: make(chan *replyMatcher), closeCtx: closeCtx, cancelCloseCtx: cancel, - log: cfg.Log, + log: log.Log, } tab, err := newTable(t, ln.Database(), cfg.Bootnodes, t.log) diff --git a/p2p/discover/v5_udp.go b/p2p/discover/v5_udp.go index b47102ee0b..6519eadb60 100644 --- a/p2p/discover/v5_udp.go +++ b/p2p/discover/v5_udp.go @@ -35,6 +35,7 @@ import ( "github.com/dominant-strategies/go-quai/p2p/enode" "github.com/dominant-strategies/go-quai/p2p/enr" "github.com/dominant-strategies/go-quai/p2p/netutil" + "github.com/sirupsen/logrus" ) const ( @@ -68,7 +69,7 @@ type UDPv5 struct { priv *ecdsa.PrivateKey localNode *enode.LocalNode db *enode.DB - log log.Logger + log *logrus.Logger clock mclock.Clock validSchemes enr.IdentityScheme @@ -145,7 +146,7 @@ func newUDPv5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) { db: ln.Database(), netrestrict: cfg.NetRestrict, priv: cfg.PrivateKey, - log: cfg.Log, + log: log.Log, validSchemes: cfg.ValidSchemes, clock: cfg.Clock, trhandlers: make(map[string]TalkRequestHandler), diff --git a/p2p/dnsdisc/client.go b/p2p/dnsdisc/client.go index a01de9bada..8292006c63 100644 --- a/p2p/dnsdisc/client.go +++ b/p2p/dnsdisc/client.go @@ -32,6 +32,7 @@ import ( "github.com/dominant-strategies/go-quai/p2p/enode" "github.com/dominant-strategies/go-quai/p2p/enr" lru "github.com/hashicorp/golang-lru" + "github.com/sirupsen/logrus" "golang.org/x/sync/singleflight" "golang.org/x/time/rate" ) @@ -53,7 +54,7 @@ type Config struct { RateLimit float64 // maximum DNS requests / second (default 3) ValidSchemes enr.IdentityScheme // acceptable ENR identity schemes (default enode.ValidSchemes) Resolver Resolver // the DNS resolver to use (defaults to system DNS) - Logger log.Logger // destination of client log messages (defaults to root logger) + Logger *logrus.Logger // destination of client log messages (defaults to root logger) } // Resolver is a DNS resolver that can query TXT records. @@ -87,7 +88,7 @@ func (cfg Config) withDefaults() Config { cfg.Resolver = new(net.Resolver) } if cfg.Logger == nil { - cfg.Logger = log.Root() + cfg.Logger = log.Log } return cfg } diff --git a/p2p/msgrate/msgrate.go b/p2p/msgrate/msgrate.go index 9364b2fe5a..de7da94756 100644 --- a/p2p/msgrate/msgrate.go +++ b/p2p/msgrate/msgrate.go @@ -24,7 +24,8 @@ import ( sync "github.com/sasha-s/go-deadlock" "time" - "github.com/dominant-strategies/go-quai/log" + log "github.com/sirupsen/logrus" + // "github.com/dominant-strategies/go-quai/log" ) // measurementImpact is the impact a single measurement has on a peer's final @@ -245,12 +246,12 @@ type Trackers struct { // purpose is to allow quicker tests. Don't use them in production. OverrideTTLLimit time.Duration - log log.Logger + log *log.Logger lock sync.RWMutex } // NewTrackers creates an empty set of trackers to be filled with peers. -func NewTrackers(log log.Logger) *Trackers { +func NewTrackers(log *log.Logger) *Trackers { return &Trackers{ trackers: make(map[string]*Tracker), roundtrip: rttMaxEstimate, @@ -421,7 +422,6 @@ func (t *Trackers) tune() { t.tuned = time.Now() t.log.Debug("Recalculated msgrate QoS values", "rtt", t.roundtrip, "confidence", t.confidence, "ttl", t.targetTimeout(), "next", t.tuned.Add(t.roundtrip)) - t.log.Trace("Debug dump of mean capacities", "caps", log.Lazy{Fn: t.meanCapacities}) } // detune reduces the tracker's confidence in order to make fresh measurements diff --git a/p2p/nat/nat.go b/p2p/nat/nat.go index 8bb8240069..354752ac21 100644 --- a/p2p/nat/nat.go +++ b/p2p/nat/nat.go @@ -97,7 +97,7 @@ const ( // Map adds a port mapping on m and keeps it alive until c is closed. // This function is typically invoked in its own goroutine. func Map(m Interface, c <-chan struct{}, protocol string, extport, intport int, name string) { - log := log.New("proto", protocol, "extport", extport, "intport", intport, "interface", m) + log := log.Log refresh := time.NewTimer(mapTimeout) defer func() { refresh.Stop() diff --git a/p2p/peer.go b/p2p/peer.go index f2005c49d4..330efdf4ac 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -124,7 +124,7 @@ func NewPeer(id enode.ID, name string, caps []Cap) *Peer { pipe, _ := net.Pipe() node := enode.SignNull(new(enr.Record), id) conn := &conn{fd: pipe, transport: nil, node: node, caps: caps, name: name} - peer := newPeer(log.Root(), conn, nil) + peer := newPeer(log.Log, conn, nil) close(peer.closed) // ensures Disconnect doesn't block return peer } @@ -229,7 +229,7 @@ func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer { disc: make(chan DiscReason), protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop closed: make(chan struct{}), - log: log.New("id", conn.node.ID(), "conn", conn.flags), + log: log, } return p } diff --git a/p2p/server.go b/p2p/server.go index 5f45d0e1db..30c5dabc44 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -442,7 +442,7 @@ func (srv *Server) Start() (err error) { srv.running = true srv.log = srv.Config.Logger if srv.log == nil { - srv.log = log.Root() + srv.log = log.Log } if srv.clock == nil { srv.clock = mclock.System{} @@ -964,7 +964,7 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) erro } else { c.node = nodeFromConn(remotePubkey, c.fd) } - clog := srv.log.New("id", c.node.ID(), "addr", c.fd.RemoteAddr(), "conn", c.flags) + clog := srv.log err = srv.checkpoint(c, srv.checkpointPostHandshake) if err != nil { clog.Trace("Rejected peer", "err", err) diff --git a/rpc/client.go b/rpc/client.go index e791b0a247..63c137f464 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -569,7 +569,7 @@ func (c *Client) dispatch(codec ServerCodec) { } case err := <-c.readErr: - conn.handler.log.Debug("RPC connection read error", "err", err) + log.Debug("RPC connection read error", "err", err) conn.close(err, lastOp) reading = false diff --git a/rpc/handler.go b/rpc/handler.go index 633285939d..6c28d82468 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -83,10 +83,10 @@ func newHandler(connCtx context.Context, conn jsonWriter, idgen func() ID, reg * cancelRoot: cancelRoot, allowSubscribe: true, serverSubs: make(map[ID]*Subscription), - log: log.Root(), + log: log.Log, } if conn.remoteAddr() != "" { - h.log = h.log.New("conn", conn.remoteAddr()) + h.log = log.New("conn: " + conn.remoteAddr()) } h.unsubscribeCb = newCallback(reflect.Value{}, reflect.ValueOf(h.unsubscribe)) return h @@ -240,7 +240,7 @@ func (h *handler) handleImmediate(msg *jsonrpcMessage) bool { return false case msg.isResponse(): h.handleResponse(msg) - h.log.Trace("Handled RPC response", "reqid", idForLog{msg.ID}, "t", time.Since(start)) + log.Trace("Handled RPC response", "reqid", idForLog{msg.ID}, "t", time.Since(start)) return true default: return false @@ -251,7 +251,7 @@ func (h *handler) handleImmediate(msg *jsonrpcMessage) bool { func (h *handler) handleSubscriptionResult(msg *jsonrpcMessage) { var result subscriptionResult if err := json.Unmarshal(msg.Params, &result); err != nil { - h.log.Debug("Dropping invalid subscription message") + log.Debug("Dropping invalid subscription message") return } if h.clientSubs[result.ID] != nil { @@ -263,7 +263,7 @@ func (h *handler) handleSubscriptionResult(msg *jsonrpcMessage) { func (h *handler) handleResponse(msg *jsonrpcMessage) { op := h.respWait[string(msg.ID)] if op == nil { - h.log.Debug("Unsolicited RPC response", "reqid", idForLog{msg.ID}) + log.Debug("Unsolicited RPC response", "reqid", idForLog{msg.ID}) return } delete(h.respWait, string(msg.ID)) @@ -292,7 +292,7 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess switch { case msg.isNotification(): h.handleCall(ctx, msg) - h.log.Debug("Served "+msg.Method, "t", time.Since(start)) + log.Debug("Served "+msg.Method, "t", time.Since(start)) return nil case msg.isCall(): resp := h.handleCall(ctx, msg) @@ -303,9 +303,9 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess if resp.Error.Data != nil { ctx = append(ctx, "errdata", resp.Error.Data) } - h.log.Warn("Served "+msg.Method, ctx...) + log.Warn("Served "+msg.Method, ctx...) } else { - h.log.Debug("Served "+msg.Method, ctx...) + log.Debug("Served "+msg.Method, ctx...) } return resp case msg.hasValidID():