|
|
@ -8,6 +8,7 @@ import ( |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// higher log level means more logging...
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
ERROR = iota |
|
|
|
ERROR = iota |
|
|
|
WARNING |
|
|
|
WARNING |
|
|
@ -53,10 +54,11 @@ var ( |
|
|
|
|
|
|
|
|
|
|
|
func (l *logStream) Printf(format string, a ...interface{}) { |
|
|
|
func (l *logStream) Printf(format string, a ...interface{}) { |
|
|
|
// describe(a)
|
|
|
|
// describe(a)
|
|
|
|
if LogLevel > l.logLevel { |
|
|
|
if LogLevel >= l.logLevel { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if no specific logger is configured for this logstrea, write to stdout...
|
|
|
|
if l.s == nil { |
|
|
|
if l.s == nil { |
|
|
|
fmt.Printf(format, a...) |
|
|
|
fmt.Printf(format, a...) |
|
|
|
return |
|
|
|
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
|
|
|
|
// is no match of the string, it will return 0 which maps to error only
|
|
|
|
// logging...perhaps this could be made more explicit
|
|
|
|
// logging...perhaps this could be made more explicit
|
|
|
|
func determineLogLevel(lstr string) int { |
|
|
|
func determineLogLevel(lstr string) int { |
|
|
|
|
|
|
|
|
|
|
|
lstrLowerCase := strings.ToLower(lstr) |
|
|
|
lstrLowerCase := strings.ToLower(lstr) |
|
|
|
return logLevelStringMap[lstrLowerCase] |
|
|
|
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) |
|
|
|
Trace.init(multi, " TRACE: ", TRACE) |
|
|
|
Debug.init(multi, " DEBUG: ", DEBUG) |
|
|
|
Debug.init(multi, " DEBUG: ", DEBUG) |
|
|
|
Info.init(multi, " INFO: ", INFO) |
|
|
|
Info.init(multi, " INFO: ", INFO) |
|
|
|
Warning.init(multi, "WARNING: ", WARNING) |
|
|
|
Warning.init(multi, "WARNING: ", WARNING) |
|
|
|
Error.init(multi, " ERROR: ", ERROR) |
|
|
|
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...) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|