use logging settings in logger
This commit is contained in:
parent
fbfeed4ee7
commit
02492cb64d
|
@ -28,9 +28,9 @@
|
|||
"failLimit": 5
|
||||
},
|
||||
"remote": "https://pterodactyl.app",
|
||||
"logger": {
|
||||
"log": {
|
||||
"path": "logs/",
|
||||
"level": "debug",
|
||||
"level": "info",
|
||||
"deleteAfterDays": 100
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
rotatelogs "github.com/lestrrat/go-file-rotatelogs"
|
||||
"github.com/rifflock/lfshook"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/schrej/wings/config"
|
||||
)
|
||||
|
||||
// ConfigureLogging configures logrus to our needs
|
||||
|
@ -15,20 +17,54 @@ func ConfigureLogging() error {
|
|||
DisableTimestamp: true,
|
||||
})
|
||||
|
||||
path := "logs/"
|
||||
path := config.Get().Log.Path
|
||||
writer := rotatelogs.New(
|
||||
path+"pterodactyld.%Y%m%d-%H%M.log",
|
||||
path+"wings.%Y%m%d-%H%M.log",
|
||||
rotatelogs.WithLinkName(path),
|
||||
rotatelogs.WithMaxAge(time.Duration(86400)*time.Second),
|
||||
rotatelogs.WithMaxAge(time.Duration(config.Get().Log.DeleteAfterDays)*time.Hour*24),
|
||||
rotatelogs.WithRotationTime(time.Duration(604800)*time.Second),
|
||||
)
|
||||
|
||||
level := config.Get().Log.Level
|
||||
|
||||
// In debug mode the log level is always debug
|
||||
if config.Get().Debug {
|
||||
level = "debug"
|
||||
}
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
// Apply log level
|
||||
switch level {
|
||||
case "debug":
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
case "info":
|
||||
log.SetLevel(log.InfoLevel)
|
||||
|
||||
case "warn":
|
||||
log.SetLevel(log.WarnLevel)
|
||||
|
||||
case "error":
|
||||
log.SetLevel(log.ErrorLevel)
|
||||
|
||||
case "fatal":
|
||||
log.SetLevel(log.FatalLevel)
|
||||
|
||||
case "panic":
|
||||
log.SetLevel(log.PanicLevel)
|
||||
}
|
||||
|
||||
log.AddHook(lfshook.NewHook(lfshook.WriterMap{
|
||||
log.DebugLevel: writer,
|
||||
log.InfoLevel: writer,
|
||||
log.WarnLevel: writer,
|
||||
log.ErrorLevel: writer,
|
||||
log.FatalLevel: writer,
|
||||
log.PanicLevel: writer,
|
||||
}))
|
||||
|
||||
log.Info("Log level: " + level)
|
||||
log.Debug("Test")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user