From 699885b61bdbe6b6b9dfb7e3e95428ab9a981fa9 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Tue, 4 Dec 2018 14:31:51 +0100 Subject: [PATCH] Second commit - system builds --- logging.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/logging.go b/logging.go index bb804a0..d40c740 100644 --- a/logging.go +++ b/logging.go @@ -8,6 +8,7 @@ import ( "strings" ) +// higher log level means more logging... const ( ERROR = iota WARNING @@ -53,10 +54,11 @@ var ( func (l *logStream) Printf(format string, a ...interface{}) { // describe(a) - if LogLevel > l.logLevel { + if LogLevel >= l.logLevel { return } + // if no specific logger is configured for this logstrea, write to stdout... if l.s == nil { fmt.Printf(format, a...) return @@ -74,7 +76,6 @@ func (l *logStream) init(m io.Writer, s string, ll int) { // is no match of the string, it will return 0 which maps to error only // logging...perhaps this could be made more explicit func determineLogLevel(lstr string) int { - lstrLowerCase := strings.ToLower(lstr) return logLevelStringMap[lstrLowerCase] } @@ -98,27 +99,9 @@ func initLogger(logFile string, logLevelStr string, logToConsole bool) { } } - // Trace = log.New(multi, " TRACE: ", log.Ldate|log.Ltime|log.Lshortfile) - // Debug = log.New(multi, " DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile) - // Info = log.New(multi, " INFO: ", log.Ldate|log.Ltime|log.Lshortfile) - // Warning = log.New(multi, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile) - // Error = log.New(multi, " ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) - // Trace = logStream{} Trace.init(multi, " TRACE: ", TRACE) Debug.init(multi, " DEBUG: ", DEBUG) Info.init(multi, " INFO: ", INFO) Warning.init(multi, "WARNING: ", WARNING) Error.init(multi, " ERROR: ", ERROR) } - -// Printf prints output to the logger if the DefaultLogger is non nil -// - otherwise it does nothing -func Printf(format string, a ...interface{}) { - // describe(a) - if DefaultLogger == nil { - fmt.Printf(format, a...) - return - } - - DefaultLogger.Printf(format, a...) -}