Skip to content

Commit

Permalink
feat: option to set log level
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Oct 1, 2024
1 parent 73a5d98 commit 816d450
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion config_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 13 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -239,13 +240,21 @@ 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,
MaxBackups: appCnf.LogSettings.MaxBackups,
MaxAge: appCnf.LogSettings.MaxAge,
}

logrus.SetLevel(logLevel)
logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.JSONFormatter{
PrettyPrint: true,
Expand Down

0 comments on commit 816d450

Please sign in to comment.