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