Clean up logging, ensure logs write to disk
This commit is contained in:
parent
a9c81f37b2
commit
0a612a71d9
52
cmd/root.go
52
cmd/root.go
|
@ -3,10 +3,13 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/NYTimes/logrotate"
|
||||||
|
"github.com/apex/log/handlers/multi"
|
||||||
"github.com/gammazero/workerpool"
|
"github.com/gammazero/workerpool"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
|
@ -111,14 +114,14 @@ func rootCmdRun(*cobra.Command, []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
printLogo()
|
printLogo()
|
||||||
if err := configureLogging(c.Debug); err != nil {
|
if err := configureLogging(c.System.LogDirectory, c.Debug); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithField("path", c.GetPath()).Info("loading configuration from path")
|
log.WithField("path", c.GetPath()).Info("loading configuration from path")
|
||||||
if c.Debug {
|
if c.Debug {
|
||||||
log.Debug("running in debug mode")
|
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{
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
|
@ -284,7 +287,7 @@ func Execute() error {
|
||||||
|
|
||||||
// Configures the global logger for Zap so that we can call it from any location
|
// 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.
|
// 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()
|
cfg := zap.NewProductionConfig()
|
||||||
if debug {
|
if debug {
|
||||||
cfg = zap.NewDevelopmentConfig()
|
cfg = zap.NewDevelopmentConfig()
|
||||||
|
@ -302,27 +305,42 @@ func configureLogging(debug bool) error {
|
||||||
|
|
||||||
zap.ReplaceGlobals(logger)
|
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.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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints the wings logo, nothing special here!
|
// Prints the wings logo, nothing special here!
|
||||||
func printLogo() {
|
func printLogo() {
|
||||||
fmt.Println()
|
fmt.Printf(colorstring.Color(`
|
||||||
fmt.Println(` ____`)
|
____
|
||||||
fmt.Println(`__ Pterodactyl _____/___/_______ _______ ______`)
|
__ [blue][bold]Pterodactyl[reset] _____/___/_______ _______ ______
|
||||||
fmt.Println(`\_____\ \/\/ / / / __ / ___/`)
|
\_____\ \/\/ / / / __ / ___/
|
||||||
fmt.Println(` \___\ / / / / /_/ /___ /`)
|
\___\ / / / / /_/ /___ /
|
||||||
fmt.Println(` \___/\___/___/___/___/___ /______/`)
|
\___/\___/___/___/___/___ /______/
|
||||||
fmt.Println(` /_______/ v` + system.Version)
|
/_______/ [bold]v%s[reset]
|
||||||
fmt.Println()
|
|
||||||
fmt.Println(`Website: https://pterodactyl.io`)
|
Copyright © 2018 - 2020 Dane Everitt & Contributors
|
||||||
fmt.Println(`Source: https://github.com/pterodactyl/wings`)
|
|
||||||
fmt.Println()
|
Website: https://pterodactyl.io
|
||||||
fmt.Println(`Copyright © 2018 - 2020 Dane Everitt & Contributors`)
|
Source: https://github.com/pterodactyl/wings
|
||||||
fmt.Println()
|
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() {
|
func exitWithConfigurationNotice() {
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -15,6 +15,7 @@ require (
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
|
||||||
github.com/Jeffail/gabs/v2 v2.2.0
|
github.com/Jeffail/gabs/v2 v2.2.0
|
||||||
github.com/Microsoft/go-winio v0.4.7 // indirect
|
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/apex/log v1.3.0
|
||||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
|
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
|
||||||
github.com/beevik/etree v1.1.0
|
github.com/beevik/etree v1.1.0
|
||||||
|
|
2
go.sum
2
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/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 h1:vOvDiY/F1avSWlCWiKJjdYKz2jVjTK3pWPHndeG4OAY=
|
||||||
github.com/Microsoft/go-winio v0.4.7/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
|
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 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
|
||||||
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
|
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=
|
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Default = New(os.Stderr)
|
var Default = New(os.Stderr, true)
|
||||||
|
|
||||||
var bold = color2.New(color2.Bold)
|
var bold = color2.New(color2.Bold)
|
||||||
|
|
||||||
|
@ -31,12 +31,14 @@ type Handler struct {
|
||||||
Padding int
|
Padding int
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(w io.Writer) *Handler {
|
func New(w io.Writer, useColors bool) *Handler {
|
||||||
if f, ok := w.(*os.File); ok {
|
if f, ok := w.(*os.File); ok {
|
||||||
|
if useColors {
|
||||||
return &Handler{Writer: colorable.NewColorable(f), Padding: 2}
|
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 {
|
type tracer interface {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user