github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/gossip/proclogger/dag_logger.go (about)

     1  package proclogger
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/unicornultrafoundation/go-u2u/native"
     7  	"github.com/unicornultrafoundation/go-u2u/logger"
     8  	"github.com/unicornultrafoundation/go-u2u/utils"
     9  )
    10  
    11  func NewLogger() *Logger {
    12  	return &Logger{
    13  		Instance: logger.New(),
    14  	}
    15  }
    16  
    17  // EventConnectionStarted starts the event logging
    18  // Not safe for concurrent use
    19  func (l *Logger) EventConnectionStarted(e native.EventPayloadI, emitted bool) func() {
    20  	l.dagSum.connected++
    21  
    22  	start := time.Now()
    23  	l.emitting = emitted
    24  	l.noSummary = true // print summary after the whole event is processed
    25  	l.lastID = e.ID()
    26  	l.lastEventTime = e.CreationTime()
    27  
    28  	return func() {
    29  		now := time.Now()
    30  		// logging for the individual item
    31  		msg := "New event"
    32  		logType := l.Log.Debug
    33  		if emitted {
    34  			msg = "New event emitted"
    35  			logType = l.Log.Info
    36  		}
    37  		logType(msg, "id", e.ID(), "parents", len(e.Parents()), "by", e.Creator(),
    38  			"frame", e.Frame(), "txs", e.Txs().Len(),
    39  			"age", utils.PrettyDuration(now.Sub(e.CreationTime().Time())), "t", utils.PrettyDuration(now.Sub(start)))
    40  		// logging for the summary
    41  		l.dagSum.totalProcessing += now.Sub(start)
    42  		l.emitting = false
    43  		l.noSummary = false
    44  		l.summary(now)
    45  	}
    46  }