better logging initialization

This commit is contained in:
Jakob Schrettenbrunner 2017-07-06 20:52:08 +02:00
parent 55ec4af875
commit e356ee5fa8

View File

@ -10,13 +10,17 @@ import (
"github.com/Pterodactyl/wings/config"
)
// ConfigureLogging configures logrus to our needs
func ConfigureLogging() error {
func InitLogging() {
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: true,
})
log.SetLevel(log.InfoLevel)
}
// ConfigureLogging configures logrus to our needs
func ConfigureLogging() error {
path := config.Get().Log.Path
writer := rotatelogs.New(
path+"wings.%Y%m%d-%H%M.log",
@ -25,6 +29,14 @@ func ConfigureLogging() error {
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
// In debug mode the log level is always debug
@ -32,8 +44,6 @@ func ConfigureLogging() error {
level = "debug"
}
log.SetLevel(log.DebugLevel)
// Apply log level
switch level {
case "debug":
@ -55,16 +65,7 @@ func ConfigureLogging() error {
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.Debug("Test")
return nil
}