From dbbf4b7e7074a25783e75ecb742421e3e49ab221 Mon Sep 17 00:00:00 2001 From: aya Date: Thu, 13 Mar 2025 12:44:08 +0200 Subject: [PATCH 1/2] Change logging to use zap instead of logrus --- go.mod | 7 +------ go.sum | 4 ---- waku/logging.go | 46 +++++++++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/go.mod b/go.mod index 166611d..dcfaad8 100644 --- a/go.mod +++ b/go.mod @@ -38,10 +38,7 @@ require ( google.golang.org/protobuf v1.34.2 ) -require ( - github.com/sirupsen/logrus v1.2.0 - github.com/waku-org/go-waku v0.8.1-0.20241028194639-dd82c24e0057 -) +require github.com/waku-org/go-waku v0.8.1-0.20241028194639-dd82c24e0057 require ( github.com/beorn7/perks v1.0.1 // indirect @@ -59,7 +56,6 @@ require ( github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/klauspost/cpuid/v2 v2.2.8 // indirect - github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -83,7 +79,6 @@ require ( golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.24.0 // indirect - golang.org/x/term v0.23.0 // indirect golang.org/x/time v0.5.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.3.0 // indirect diff --git a/go.sum b/go.sum index 1d53bd8..dcf97e7 100644 --- a/go.sum +++ b/go.sum @@ -297,7 +297,6 @@ github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg= github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= -github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= @@ -515,7 +514,6 @@ github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 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= @@ -734,8 +732,6 @@ golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= -golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/waku/logging.go b/waku/logging.go index 6d610aa..8be327c 100644 --- a/waku/logging.go +++ b/waku/logging.go @@ -3,41 +3,45 @@ package waku import ( "sync" - "github.com/sirupsen/logrus" + "go.uber.org/zap" ) var ( - once sync.Once - instance *logrus.Logger + once sync.Once + sugar *zap.SugaredLogger ) -// _getLogger ensures we always return the same logger instance (private function) -func _getLogger() *logrus.Logger { +func _getLogger() *zap.SugaredLogger { once.Do(func() { - instance = logrus.New() - instance.SetFormatter(&logrus.TextFormatter{ - FullTimestamp: true, - }) - instance.SetLevel(logrus.DebugLevel) // Set default log level + + config := zap.NewDevelopmentConfig() + l, err := config.Build() + if err != nil { + panic(err) + } + sugar = l.Sugar() }) - return instance + return sugar +} + +func SetLogger(newLogger *zap.Logger) { + once.Do(func() {}) + + sugar = newLogger.Sugar() } -// Debug logs a debug message func Debug(msg string, args ...interface{}) { - _getLogger().WithFields(logrus.Fields{}).Debugf(msg, args...) + _getLogger().Debugf(msg, args...) } -// Info logs an info message func Info(msg string, args ...interface{}) { - _getLogger().WithFields(logrus.Fields{}).Infof(msg, args...) -} - -// Error logs an error message -func Error(msg string, args ...interface{}) { - _getLogger().WithFields(logrus.Fields{}).Errorf(msg, args...) + _getLogger().Infof(msg, args...) } func Warn(msg string, args ...interface{}) { - _getLogger().WithFields(logrus.Fields{}).Warnf(msg, args...) + _getLogger().Warnf(msg, args...) +} + +func Error(msg string, args ...interface{}) { + _getLogger().Errorf(msg, args...) } From 5a9a4ce4b351d2b211bb56905ac3aa008a74a402 Mon Sep 17 00:00:00 2001 From: aya Date: Thu, 13 Mar 2025 15:06:12 +0200 Subject: [PATCH 2/2] update logger --- waku/logging.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/waku/logging.go b/waku/logging.go index 8be327c..66292fe 100644 --- a/waku/logging.go +++ b/waku/logging.go @@ -13,8 +13,9 @@ var ( func _getLogger() *zap.SugaredLogger { once.Do(func() { - config := zap.NewDevelopmentConfig() + config.DisableCaller = true + config.EncoderConfig.CallerKey = "" l, err := config.Build() if err != nil { panic(err)