diff --git a/logging.go b/logging.go index 9810706..25d129a 100644 --- a/logging.go +++ b/logging.go @@ -8,6 +8,7 @@ package logging import ( + "errors" "fmt" "io" "log" @@ -88,17 +89,26 @@ func (l *logStream) init(m io.Writer, s string, ll int) { // function to parse string representation of log level into integer - if there // 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 { +func determineLogLevel(lstr string) (returnVal int, err error) { lstrLowerCase := strings.ToLower(lstr) - return logLevelStringMap[lstrLowerCase] + var validLogLevel bool + if returnVal, validLogLevel = logLevelStringMap[lstrLowerCase]; validLogLevel == false { + err = errors.New("Invalid Log Level") + } + return } // InitLogger initializes the logging system -func InitLogger(logFile string, logLevelStr string, logToConsole bool) { +func InitLogger(logFile string, logLevelStr string, logToConsole bool) (err error) { - LogLevel = determineLogLevel(logLevelStr) + if LogLevel, err = determineLogLevel(logLevelStr); err != nil { + return + } - file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + var file *os.File + if file, err = os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666); err != nil { + return + } var multi io.Writer @@ -118,4 +128,6 @@ func InitLogger(logFile string, logLevelStr string, logToConsole bool) { Info.init(multi, " INFO: ", INFO) Warning.init(multi, "WARNING: ", WARNING) Error.init(multi, " ERROR: ", ERROR) + + return }