live-streamer/logger/logger.go

35 lines
768 B
Go
Raw Permalink Normal View History

package logger
import (
"os"
"strings"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
2024-10-29 05:11:14 -04:00
func NewLogger(level string) *zap.Logger {
var logLevel zapcore.Level
2024-10-29 05:11:14 -04:00
switch strings.ToLower(level) {
case "info":
logLevel = zap.InfoLevel
case "error":
logLevel = zap.ErrorLevel
case "warn":
logLevel = zap.WarnLevel
case "debug":
logLevel = zap.DebugLevel
case "panic":
logLevel = zap.PanicLevel
}
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
consoleWriter := zapcore.AddSync(os.Stdout)
consoleCore := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderConfig), consoleWriter, logLevel)
2024-10-29 05:11:14 -04:00
logger := zap.New(consoleCore)
return logger
}