package logger import ( "os" "strings" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) func NewLogger(level string) *zap.Logger { var logLevel zapcore.Level 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) logger := zap.New(consoleCore) return logger }