diff options
Diffstat (limited to 'src/logger.go')
-rw-r--r-- | src/logger.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/logger.go b/src/logger.go index 117fe5b..827f9e9 100644 --- a/src/logger.go +++ b/src/logger.go @@ -1,6 +1,8 @@ package main import ( + "io" + "io/ioutil" "log" "os" ) @@ -17,17 +19,30 @@ type Logger struct { Error *log.Logger } -func NewLogger() *Logger { +func NewLogger(level int) *Logger { + output := os.Stdout logger := new(Logger) - logger.Debug = log.New(os.Stdout, + + logErr, logInfo, logDebug := func() (io.Writer, io.Writer, io.Writer) { + if level >= LogLevelDebug { + return output, output, output + } + if level >= LogLevelInfo { + return output, output, ioutil.Discard + } + return output, ioutil.Discard, ioutil.Discard + }() + + logger.Debug = log.New(logDebug, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile, ) - logger.Info = log.New(os.Stdout, + + logger.Info = log.New(logInfo, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile, ) - logger.Error = log.New(os.Stdout, + logger.Error = log.New(logErr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile, ) |