Skip to content

Commit

Permalink
info to stdout; error and warning to stderr
Browse files Browse the repository at this point in the history
I'm not an experienced Go developer, but it seems to work and fixes [go-acme#1531]
  • Loading branch information
d0m84 authored Nov 22, 2022
1 parent 1b56aa0 commit 0927d1d
Showing 1 changed file with 13 additions and 9 deletions.
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...)
}

0 comments on commit 0927d1d

Please sign in to comment.