diff --git a/core/config/config.go b/core/config/config.go index 13d3ad3..75ce106 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -7,6 +7,7 @@ import ( "fmt" "os" + "github.com/alt-research/avs/core" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/urfave/cli" @@ -110,7 +111,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) { } } - logger, err := sdklogging.NewZapLogger(configRaw.Environment) + logger, err := core.NewZapLogger(configRaw.Environment) if err != nil { return nil, err } diff --git a/core/logger.go b/core/logger.go new file mode 100644 index 0000000..2a02a13 --- /dev/null +++ b/core/logger.go @@ -0,0 +1,80 @@ +package core + +import ( + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + + sdklogging "github.com/Layr-Labs/eigensdk-go/logging" +) + +type ZapLogger struct { + logger *zap.Logger +} + +var _ sdklogging.Logger = (*ZapLogger)(nil) + +func NewZapLogger(env sdklogging.LogLevel) (sdklogging.Logger, error) { + config := zap.NewProductionConfig() + if env == sdklogging.Development { + config = zap.NewDevelopmentConfig() + } + + config.DisableStacktrace = true + config.Encoding = "console" + config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder + config.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder + + logger, err := config.Build(zap.AddCallerSkip(1)) + if err != nil { + panic(err) + } + return &ZapLogger{ + logger: logger, + }, nil +} + +func (z *ZapLogger) Debug(msg string, tags ...any) { + z.logger.Sugar().Debugw(msg, tags...) +} + +func (z *ZapLogger) Info(msg string, tags ...any) { + z.logger.Sugar().Infow(msg, tags...) +} + +func (z *ZapLogger) Warn(msg string, tags ...any) { + z.logger.Sugar().Warnw(msg, tags...) +} + +func (z *ZapLogger) Error(msg string, tags ...any) { + z.logger.Sugar().Errorw(msg, tags...) +} + +func (z *ZapLogger) Fatal(msg string, tags ...any) { + z.logger.Sugar().Fatalw(msg, tags...) +} + +func (z *ZapLogger) Debugf(template string, args ...interface{}) { + z.logger.Sugar().Debugf(template, args...) +} + +func (z *ZapLogger) Infof(template string, args ...interface{}) { + z.logger.Sugar().Infof(template, args...) +} + +func (z *ZapLogger) Warnf(template string, args ...interface{}) { + z.logger.Sugar().Warnf(template, args...) +} + +func (z *ZapLogger) Errorf(template string, args ...interface{}) { + z.logger.Sugar().Errorf(template, args...) +} + +func (z *ZapLogger) Fatalf(template string, args ...interface{}) { + z.logger.Sugar().Fatalf(template, args...) +} + +func (z *ZapLogger) With(tags ...any) sdklogging.Logger { + return &ZapLogger{ + logger: z.logger.Sugar().With(tags...).Desugar(), + } +} diff --git a/go.mod b/go.mod index d67329e..3d120e5 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/sourcegraph/jsonrpc2 v0.2.0 github.com/urfave/cli v1.22.14 go.uber.org/mock v0.4.0 + go.uber.org/zap v1.27.0 golang.org/x/crypto v0.18.0 ) @@ -50,7 +51,6 @@ require ( github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.27.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/mod v0.16.0 // indirect golang.org/x/sync v0.5.0 // indirect diff --git a/operator/operator.go b/operator/operator.go index 5180fb2..4d98e24 100644 --- a/operator/operator.go +++ b/operator/operator.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/prometheus/client_golang/prometheus" + "github.com/alt-research/avs/core" "github.com/alt-research/avs/core/alert" "github.com/alt-research/avs/core/chainio" "github.com/alt-research/avs/core/config" @@ -198,7 +199,7 @@ func NewOperatorFromConfig(cfg config.NodeConfig) (*Operator, error) { } else { logLevel = sdklogging.Development } - logger, err := sdklogging.NewZapLogger(logLevel) + logger, err := core.NewZapLogger(logLevel) if err != nil { return nil, err }