Skip to content

Commit

Permalink
crawler: update logger
Browse files Browse the repository at this point in the history
  • Loading branch information
iquidus committed Dec 12, 2023
1 parent 69a09a1 commit 4b93222
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions crawler/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,13 @@ func (c *Crawler) syncBlock(block common.Block, task *syncronizer.Task) {
c.state.Cache.Push(block)

// log
c.log(block.Number, len(block.Logs))
c.log(block.Number, len(block.Transactions), len(block.Logs))
}

func (c *Crawler) log(blockNo uint64, txns int) {
func (c *Crawler) log(blockNo uint64, txns int, logs int) {
c.logChan <- &logObject{
blockNo: blockNo,
txns: txns,
logs: logs,
}
}
14 changes: 10 additions & 4 deletions crawler/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ type logObject struct {
blockNo uint64
blocks int
txns int
logs int
}

func (l *logObject) add(o *logObject) {
l.blockNo = o.blockNo
l.blocks++
l.txns += o.txns
l.logs += o.logs
}

func (l *logObject) clear() {
l.blockNo = 0
l.blocks = 0
l.txns = 0
l.logs = 0
}

func startLogger(c chan *logObject, logger log.Logger) {
Expand All @@ -32,6 +35,7 @@ func startLogger(c chan *logObject, logger log.Logger) {
0,
0,
0,
0,
}
logLoop:
for {
Expand All @@ -40,19 +44,21 @@ func startLogger(c chan *logObject, logger log.Logger) {
stats.add(lo)
if stats.blocks >= 1000 || time.Now().After(start.Add(time.Minute)) {
logger.Info("Imported new chain segment",
"blocks", stats.blocks,
"head", stats.blockNo,
"transactions", stats.txns,
"blocks", stats.blocks,
"txns", stats.txns,
"logs", stats.logs,
"took", time.Since(start))
stats.clear()
start = time.Now()
}
} else {
if stats.blocks > 0 {
logger.Info("Imported new chain segment",
"blocks", stats.blocks,
"head", stats.blockNo,
"transactions", stats.txns,
"blocks", stats.blocks,
"txns", stats.txns,
"logs", stats.logs,
"took", time.Since(start))
}
break logLoop
Expand Down

0 comments on commit 4b93222

Please sign in to comment.