diff --git a/cmd/root.go b/cmd/root.go index 1c298d9..f852869 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,10 +3,13 @@ package cmd import ( "crypto/tls" "fmt" + "github.com/NYTimes/logrotate" + "github.com/apex/log/handlers/multi" "github.com/gammazero/workerpool" "net/http" "os" "path" + "path/filepath" "strings" "github.com/apex/log" @@ -111,14 +114,14 @@ func rootCmdRun(*cobra.Command, []string) { } printLogo() - if err := configureLogging(c.Debug); err != nil { + if err := configureLogging(c.System.LogDirectory, c.Debug); err != nil { panic(err) } log.WithField("path", c.GetPath()).Info("loading configuration from path") if c.Debug { log.Debug("running in debug mode") - log.Info("certificate checking is disabled") + log.Warn("certificate checking is disabled") http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{ InsecureSkipVerify: true, @@ -284,7 +287,7 @@ func Execute() error { // Configures the global logger for Zap so that we can call it from any location // in the code without having to pass around a logger instance. -func configureLogging(debug bool) error { +func configureLogging(logDir string, debug bool) error { cfg := zap.NewProductionConfig() if debug { cfg = zap.NewDevelopmentConfig() @@ -302,27 +305,42 @@ func configureLogging(debug bool) error { zap.ReplaceGlobals(logger) - log.SetHandler(cli.Default) + p := filepath.Join(logDir, "/wings.log") + w, err := logrotate.NewFile(p) + if err != nil { + panic(errors.WithMessage(err, "failed to open process log file")) + } + log.SetLevel(log.DebugLevel) + log.SetHandler(multi.New( + cli.Default, + cli.New(w.File, false), + )) + + log.WithField("path", p).Info("writing log files to disk") return nil } // Prints the wings logo, nothing special here! func printLogo() { - fmt.Println() - fmt.Println(` ____`) - fmt.Println(`__ Pterodactyl _____/___/_______ _______ ______`) - fmt.Println(`\_____\ \/\/ / / / __ / ___/`) - fmt.Println(` \___\ / / / / /_/ /___ /`) - fmt.Println(` \___/\___/___/___/___/___ /______/`) - fmt.Println(` /_______/ v` + system.Version) - fmt.Println() - fmt.Println(`Website: https://pterodactyl.io`) - fmt.Println(`Source: https://github.com/pterodactyl/wings`) - fmt.Println() - fmt.Println(`Copyright © 2018 - 2020 Dane Everitt & Contributors`) - fmt.Println() + fmt.Printf(colorstring.Color(` + ____ +__ [blue][bold]Pterodactyl[reset] _____/___/_______ _______ ______ +\_____\ \/\/ / / / __ / ___/ + \___\ / / / / /_/ /___ / + \___/\___/___/___/___/___ /______/ + /_______/ [bold]v%s[reset] + +Copyright © 2018 - 2020 Dane Everitt & Contributors + +Website: https://pterodactyl.io + Source: https://github.com/pterodactyl/wings +License: https://github.com/pterodactyl/wings/blob/develop/LICENSE + +This software is made available under the terms of the MIT license. +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software.%s`), system.Version, "\n\n") } func exitWithConfigurationNotice() { diff --git a/go.mod b/go.mod index 0de71c2..f458689 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/Jeffail/gabs/v2 v2.2.0 github.com/Microsoft/go-winio v0.4.7 // indirect + github.com/NYTimes/logrotate v1.0.0 github.com/apex/log v1.3.0 github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a github.com/beevik/etree v1.1.0 diff --git a/go.sum b/go.sum index 2ac6433..833a480 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/Jeffail/gabs/v2 v2.2.0 h1:7touC+WzbQ7LO5+mwgxT44miyTqAVCOlIWLA6PiIB5w github.com/Jeffail/gabs/v2 v2.2.0/go.mod h1:xCn81vdHKxFUuWWAaD5jCTQDNPBMh5pPs9IJ+NcziBI= github.com/Microsoft/go-winio v0.4.7 h1:vOvDiY/F1avSWlCWiKJjdYKz2jVjTK3pWPHndeG4OAY= github.com/Microsoft/go-winio v0.4.7/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= +github.com/NYTimes/logrotate v1.0.0 h1:6jFGbon6jOtpy3t3kwZZKS4Gdmf1C/Wv5J4ll4Xn5yk= +github.com/NYTimes/logrotate v1.0.0/go.mod h1:GxNz1cSw1c6t99PXoZlw+nm90H6cyQyrH66pjVv7x88= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= diff --git a/loggers/cli/cli.go b/loggers/cli/cli.go index af71c31..fab7368 100644 --- a/loggers/cli/cli.go +++ b/loggers/cli/cli.go @@ -13,7 +13,7 @@ import ( "time" ) -var Default = New(os.Stderr) +var Default = New(os.Stderr, true) var bold = color2.New(color2.Bold) @@ -31,12 +31,14 @@ type Handler struct { Padding int } -func New(w io.Writer) *Handler { +func New(w io.Writer, useColors bool) *Handler { if f, ok := w.(*os.File); ok { - return &Handler{Writer: colorable.NewColorable(f), Padding: 2} + if useColors { + return &Handler{Writer: colorable.NewColorable(f), Padding: 2} + } } - return &Handler{Writer: w, Padding: 2} + return &Handler{Writer: colorable.NewNonColorable(w), Padding: 2} } type tracer interface {