2023-10-12 18:36:34 +00:00
|
|
|
package logger
|
|
|
|
|
2024-08-15 16:25:15 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2023-10-12 18:36:34 +00:00
|
|
|
|
2024-08-15 16:25:15 +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
|
|
|
|
|
|
|
}
|