Clean up logging, ensure logs write to disk

This commit is contained in:
Dane Everitt 2020-08-03 20:35:48 -07:00
parent a9c81f37b2
commit 0a612a71d9
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 44 additions and 21 deletions

View File

@ -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() {

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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 {
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 {