Add way to specify log level
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/debridmediamanager/zurg/internal/config"
|
"github.com/debridmediamanager/zurg/internal/config"
|
||||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||||
|
|
||||||
cmap "github.com/orcaman/concurrent-map/v2"
|
cmap "github.com/orcaman/concurrent-map/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,26 @@ type Logger struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewLogger(logPath string) *Logger {
|
func NewLogger(logPath string) *Logger {
|
||||||
|
envLogLevel := os.Getenv("LOG_LEVEL")
|
||||||
|
var zapLevel zapcore.Level
|
||||||
|
|
||||||
|
switch envLogLevel {
|
||||||
|
case "DEBUG":
|
||||||
|
zapLevel = zapcore.DebugLevel
|
||||||
|
case "INFO":
|
||||||
|
zapLevel = zapcore.InfoLevel
|
||||||
|
case "WARN":
|
||||||
|
zapLevel = zapcore.WarnLevel
|
||||||
|
case "ERROR":
|
||||||
|
zapLevel = zapcore.ErrorLevel
|
||||||
|
case "FATAL":
|
||||||
|
zapLevel = zapcore.FatalLevel
|
||||||
|
default:
|
||||||
|
zapLevel = zapcore.InfoLevel
|
||||||
|
}
|
||||||
|
|
||||||
zapCfg := zap.NewDevelopmentConfig()
|
zapCfg := zap.NewDevelopmentConfig()
|
||||||
|
zapCfg.Level.SetLevel(zapLevel)
|
||||||
|
|
||||||
consoleCfg := zapcore.EncoderConfig{
|
consoleCfg := zapcore.EncoderConfig{
|
||||||
TimeKey: "time",
|
TimeKey: "time",
|
||||||
@@ -45,6 +64,7 @@ func NewLogger(logPath string) *Logger {
|
|||||||
EncodeDuration: zapcore.StringDurationEncoder,
|
EncodeDuration: zapcore.StringDurationEncoder,
|
||||||
}
|
}
|
||||||
fileEncoder := zapcore.NewConsoleEncoder(fileCfg)
|
fileEncoder := zapcore.NewConsoleEncoder(fileCfg)
|
||||||
|
|
||||||
// Set up file logging with overwrite mode
|
// Set up file logging with overwrite mode
|
||||||
logFile, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
logFile, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user