34 lines
759 B
Go
34 lines
759 B
Go
|
package logging
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"go.uber.org/zap"
|
||
|
"go.uber.org/zap/zapcore"
|
||
|
)
|
||
|
|
||
|
func CreateLogger(logLevel string) *zap.Logger {
|
||
|
encoderCfg := zap.NewProductionEncoderConfig()
|
||
|
encoderCfg.TimeKey = "time"
|
||
|
encoderCfg.EncodeTime = zapcore.TimeEncoderOfLayout(time.StampMilli)
|
||
|
|
||
|
level := zap.NewAtomicLevelAt(zap.InfoLevel)
|
||
|
zapLevel, err := zap.ParseAtomicLevel(logLevel)
|
||
|
if err == nil {
|
||
|
level = zapLevel
|
||
|
}
|
||
|
|
||
|
config := zap.Config{
|
||
|
Level: level,
|
||
|
Development: false,
|
||
|
DisableCaller: false,
|
||
|
DisableStacktrace: false,
|
||
|
Sampling: nil,
|
||
|
Encoding: "json",
|
||
|
EncoderConfig: encoderCfg,
|
||
|
OutputPaths: []string{"stdout"},
|
||
|
ErrorOutputPaths: []string{"stderr"},
|
||
|
}
|
||
|
return zap.Must(config.Build())
|
||
|
}
|