From 816d450364a611a442d0c64af9e957f675b694d7 Mon Sep 17 00:00:00 2001 From: "Jibon L. Costa" Date: Tue, 1 Oct 2024 10:05:25 +0200 Subject: [PATCH] feat: option to set log level --- config_sample.yaml | 4 +++- pkg/config/config.go | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/config_sample.yaml b/config_sample.yaml index e8d59f2b..ad8d128a 100644 --- a/config_sample.yaml +++ b/config_sample.yaml @@ -45,11 +45,13 @@ room_default_settings: max_num_breakout_rooms: 6 log_settings: log_file: "./log/plugNmeet.log" - # maxsize of log file in MB + # maxsize of the log file in MB maxsize: 20 maxbackups: 4 # max age of log before rotates in days maxage: 2 + # info, warn, error, fatal, debug or panic + log_level: "info" livekit_info: host: "http://host.docker.internal:7880" api_key: "APIiYAA5w37Cfo2" diff --git a/pkg/config/config.go b/pkg/config/config.go index 8e3b76a9..6fd3400d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -63,10 +63,11 @@ type PrometheusConf struct { } type LogSettings struct { - LogFile string `yaml:"log_file"` - MaxSize int `yaml:"max_size"` - MaxBackups int `yaml:"max_backups"` - MaxAge int `yaml:"max_age"` + LogFile string `yaml:"log_file"` + MaxSize int `yaml:"max_size"` + MaxBackups int `yaml:"max_backups"` + MaxAge int `yaml:"max_age"` + LogLevel *string `yaml:"log_level"` } type LivekitInfo struct { @@ -239,6 +240,13 @@ func setLogger() { p = filepath.Join(appCnf.RootWorkingDir, p) } + logLevel := logrus.WarnLevel + if appCnf.LogSettings.LogLevel != nil && *appCnf.LogSettings.LogLevel != "" { + if lv, err := logrus.ParseLevel(strings.ToLower(*appCnf.LogSettings.LogLevel)); err == nil { + logLevel = lv + } + } + logWriter := &lumberjack.Logger{ Filename: p, MaxSize: appCnf.LogSettings.MaxSize, @@ -246,6 +254,7 @@ func setLogger() { MaxAge: appCnf.LogSettings.MaxAge, } + logrus.SetLevel(logLevel) logrus.SetReportCaller(true) logrus.SetFormatter(&logrus.JSONFormatter{ PrettyPrint: true,