Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made default logger to print output to stderr instead of stdout #782

Merged
merged 1 commit into from Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions config.go
Expand Up @@ -25,8 +25,6 @@ var lookupPaths = []string{"", "./config", "/config", "../", "../config", "../..
var ConfigName = "database.yml"

func init() {
SetLogger(defaultLogger)
sio4 marked this conversation as resolved.
Show resolved Hide resolved

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

type logger func(lvl logging.Level, s string, args ...interface{})
sio4 marked this conversation as resolved.
Show resolved Hide resolved

// 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{})) {
sio4 marked this conversation as resolved.
Show resolved Hide resolved
log = logger
}

var defaultStdLogger = stdlog.New(os.Stderr, "[POP] ", stdlog.LstdFlags)
sio4 marked this conversation as resolved.
Show resolved Hide resolved

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{}) {
sio4 marked this conversation as resolved.
Show resolved Hide resolved
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
}