From 7276fc1d4b4264268b87138862d57423cf0ccaba Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 29 Jun 2015 14:22:20 +0100 Subject: [PATCH] Wire up selection of logging levels to match old behaviour - note that all output is now going to stderr. --- common/init.go | 7 +------ common/logging.go | 38 +++++++++++++++----------------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/common/init.go b/common/init.go index 0e1968f7..297a339e 100644 --- a/common/init.go +++ b/common/init.go @@ -1,10 +1,5 @@ package common -import ( - "io/ioutil" - "os" -) - func init() { - InitLogging(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr) + InitDefaultLogging(false) } diff --git a/common/logging.go b/common/logging.go index 9c971d09..daf144e0 100644 --- a/common/logging.go +++ b/common/logging.go @@ -3,8 +3,6 @@ package common import ( "bytes" "fmt" - "io" - "io/ioutil" "os" "strings" @@ -40,33 +38,27 @@ var ( ) var ( - Log *logrus.Logger - Info *logrus.Logger - debugF bool + Log *logrus.Logger + Info *logrus.Logger ) -func InitLogging(debugHandle io.Writer, - infoHandle io.Writer, - warningHandle io.Writer, - errorHandle io.Writer) { - - Info = &logrus.Logger{ - Out: infoHandle, - Formatter: standardTextFormatter, - Hooks: make(logrus.LevelHooks), - Level: logrus.InfoLevel, +func InitLogging(level logrus.Level) { + if Info == nil { + Info = &logrus.Logger{ + Out: os.Stderr, + Formatter: standardTextFormatter, + Hooks: make(logrus.LevelHooks), + Level: level, + } + Log = Info } - Log = Info + Info.Level = level } func InitDefaultLogging(debug bool) { - if debug == debugF { - return - } - debugF = debug - debugOut := ioutil.Discard + level := logrus.InfoLevel if debug { - debugOut = os.Stderr + level = logrus.DebugLevel } - InitLogging(debugOut, os.Stdout, os.Stdout, os.Stderr) + InitLogging(level) }