Skip to content

Commit

Permalink
made default logger to print output to stderr instead of stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Sep 24, 2022
1 parent b0c857d commit df9e1b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 0 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ var lookupPaths = []string{"", "./config", "/config", "../", "../config", "../..
var ConfigName = "database.yml"

func init() {
SetLogger(defaultLogger)

ap := os.Getenv("APP_PATH")
if ap != "" {
_ = AddLookupPaths(ap)
Expand Down
20 changes: 7 additions & 13 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import (
"github.com/gobuffalo/pop/v6/logging"
)

type logger func(lvl logging.Level, s string, args ...interface{})

// Debug mode, to toggle verbose log traces
var Debug = false

// Color mode, to toggle colored logs
var Color = true

var log logger
// SetLogger overrides the default logger.
func SetLogger(logger func(level logging.Level, s string, args ...interface{})) {
log = logger
}

var defaultStdLogger = stdlog.New(os.Stderr, "[POP] ", stdlog.LstdFlags)

var defaultStdLogger = stdlog.New(os.Stdout, "[POP] ", stdlog.LstdFlags)
var defaultLogger = func(lvl logging.Level, s string, args ...interface{}) {
var log = func(lvl logging.Level, s string, args ...interface{}) {
if !Debug && lvl <= logging.Debug {
return
}
Expand Down Expand Up @@ -48,11 +50,3 @@ var defaultLogger = func(lvl logging.Level, s string, args ...interface{}) {
}
defaultStdLogger.Println(s)
}

// SetLogger overrides the default logger.
//
// The logger must implement the following interface:
// type logger func(lvl logging.Level, s string, args ...interface{})
func SetLogger(l logger) {
log = l
}

0 comments on commit df9e1b2

Please sign in to comment.