better logging initialization
This commit is contained in:
parent
55ec4af875
commit
e356ee5fa8
|
@ -10,13 +10,17 @@ import (
|
||||||
"github.com/Pterodactyl/wings/config"
|
"github.com/Pterodactyl/wings/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigureLogging configures logrus to our needs
|
func InitLogging() {
|
||||||
func ConfigureLogging() error {
|
|
||||||
|
|
||||||
log.SetFormatter(&log.TextFormatter{
|
log.SetFormatter(&log.TextFormatter{
|
||||||
DisableTimestamp: true,
|
DisableTimestamp: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
log.SetLevel(log.InfoLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigureLogging configures logrus to our needs
|
||||||
|
func ConfigureLogging() error {
|
||||||
|
|
||||||
path := config.Get().Log.Path
|
path := config.Get().Log.Path
|
||||||
writer := rotatelogs.New(
|
writer := rotatelogs.New(
|
||||||
path+"wings.%Y%m%d-%H%M.log",
|
path+"wings.%Y%m%d-%H%M.log",
|
||||||
|
@ -25,6 +29,14 @@ func ConfigureLogging() error {
|
||||||
rotatelogs.WithRotationTime(time.Duration(604800)*time.Second),
|
rotatelogs.WithRotationTime(time.Duration(604800)*time.Second),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
log.AddHook(lfshook.NewHook(lfshook.WriterMap{
|
||||||
|
log.DebugLevel: writer,
|
||||||
|
log.InfoLevel: writer,
|
||||||
|
log.WarnLevel: writer,
|
||||||
|
log.ErrorLevel: writer,
|
||||||
|
log.FatalLevel: writer,
|
||||||
|
}))
|
||||||
|
|
||||||
level := config.Get().Log.Level
|
level := config.Get().Log.Level
|
||||||
|
|
||||||
// In debug mode the log level is always debug
|
// In debug mode the log level is always debug
|
||||||
|
@ -32,8 +44,6 @@ func ConfigureLogging() error {
|
||||||
level = "debug"
|
level = "debug"
|
||||||
}
|
}
|
||||||
|
|
||||||
log.SetLevel(log.DebugLevel)
|
|
||||||
|
|
||||||
// Apply log level
|
// Apply log level
|
||||||
switch level {
|
switch level {
|
||||||
case "debug":
|
case "debug":
|
||||||
|
@ -55,16 +65,7 @@ func ConfigureLogging() error {
|
||||||
log.SetLevel(log.PanicLevel)
|
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.Info("Log level: " + level)
|
log.Info("Log level: " + level)
|
||||||
log.Debug("Test")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user