tools: ensure logging path exists

This commit is contained in:
Jakob Schrettenbrunner 2017-09-16 13:56:20 +02:00
parent 5ed3bb2a0c
commit e92e3e4e66

View File

@ -1,8 +1,11 @@
package tools
import (
"os"
"time"
"github.com/Pterodactyl/wings/constants"
rotatelogs "github.com/lestrrat/go-file-rotatelogs"
"github.com/rifflock/lfshook"
log "github.com/sirupsen/logrus"
@ -11,6 +14,7 @@ import (
"github.com/Pterodactyl/wings/config"
)
// InitLogging initalizes the logging library for first use.
func InitLogging() {
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: true,
@ -19,10 +23,13 @@ func InitLogging() {
log.SetLevel(log.InfoLevel)
}
// ConfigureLogging configures logrus to our needs
// ConfigureLogging applies the configuration to the logging library.
func ConfigureLogging() error {
path := viper.GetString(config.LogPath)
if err := os.MkdirAll(path, constants.DefaultFilePerms); err != nil {
return err
}
writer := rotatelogs.New(
path+"wings.%Y%m%d-%H%M.log",
rotatelogs.WithLinkName(path),