Merge pull request #53 from waku-org/logging-zap

Change logging to use zap instead of logrus
This commit is contained in:
AYAHASSAN287 2025-03-13 16:20:00 +03:00 committed by GitHub
commit ec9abe5249
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 31 deletions

7
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -3,41 +3,46 @@ 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()
config.DisableCaller = true
config.EncoderConfig.CallerKey = ""
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...)
}