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

info to stdout; error and warning to stderr #1760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"os"
)

// Logger is an optional custom logger.
var Logger StdLogger = log.New(os.Stderr, "", log.LstdFlags)
// Logger is an optional custom logger to stdout.
// ErrLogger is an optional custom logger to stderr.
var Logger StdLogger = log.New(os.Stdout, "", log.LstdFlags)
var ErrLogger StdLogger = log.New(os.Stderr, "", log.LstdFlags)

// StdLogger interface for Standard Logger.
// StdLogger interface.
type StdLogger interface {
Fatal(args ...interface{})
Fatalln(args ...interface{})
Expand All @@ -19,15 +21,15 @@ type StdLogger interface {
}

// Fatal writes a log entry.
// It uses Logger if not nil, otherwise it uses the default log.Logger.
// It uses ErrLogger if not nil, otherwise it uses the default log.Logger.
func Fatal(args ...interface{}) {
Logger.Fatal(args...)
ErrLogger.Fatal(args...)
}

// Fatalf writes a log entry.
// It uses Logger if not nil, otherwise it uses the default log.Logger.
// It uses ErrLogger if not nil, otherwise it uses the default log.Logger.
func Fatalf(format string, args ...interface{}) {
Logger.Fatalf(format, args...)
ErrLogger.Fatalf(format, args...)
}

// Print writes a log entry.
Expand All @@ -49,11 +51,13 @@ func Printf(format string, args ...interface{}) {
}

// Warnf writes a log entry.
// It uses ErrLogger if not nil, otherwise it uses the default log.Logger.
func Warnf(format string, args ...interface{}) {
Printf("[WARN] "+format, args...)
ErrLogger.Printf("[WARN] "+format, args...)
}

// Infof writes a log entry.
// It uses Logger if not nil, otherwise it uses the default log.Logger.
func Infof(format string, args ...interface{}) {
Printf("[INFO] "+format, args...)
Logger.Printf("[INFO] "+format, args...)
}