polycule-connect/polyculeconnect/logger/logger.go

29 lines
555 B
Go
Raw Permalink Normal View History

2023-10-12 18:36:34 +00:00
package logger
import (
"fmt"
2023-10-12 18:36:34 +00:00
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var L *zap.SugaredLogger
func Init(level zap.AtomicLevel) {
conf := zap.Config{
Level: level,
Encoding: "console",
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
}
conf.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
if l, err := conf.Build(); err != nil {
panic(fmt.Errorf("failed to init logger: %w", err))
} else {
L = l.Sugar()
}
2023-10-12 18:36:34 +00:00
}