From 322fb34aeac3a8746f82e89a9c54b9936778289c Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sun, 28 Jan 2018 22:00:09 +0100 Subject: [PATCH] logger: add level support Signed-off-by: Maciek Borzecki --- logger/logger.go | 13 +++++++++++++ logger/logrus.go | 24 +++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index 71d1a2a..ad7444b 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -35,4 +35,17 @@ type Logger interface { Print(args ...interface{}) Printf(format string, args ...interface{}) Println(args ...interface{}) + + SetLevel(level Level) } + +type Level int + +const ( + PanicLevel Level = iota + FatalLevel + ErrorLevel + WarnLevel + InfoLevel + DebugLevel +) diff --git a/logger/logrus.go b/logger/logrus.go index c4a0b0f..bbf55dd 100644 --- a/logger/logrus.go +++ b/logger/logrus.go @@ -17,19 +17,29 @@ import ( "github.com/Sirupsen/logrus" ) -var log *logrus.Logger +type logger struct { + logrus.Logger +} + +var log *logger func init() { - log = &logrus.Logger{ - Out: os.Stderr, - Formatter: &logrus.TextFormatter{ - FullTimestamp: true, + log = &logger{ + Logger: logrus.Logger{ + Out: os.Stderr, + Formatter: &logrus.TextFormatter{ + FullTimestamp: true, + }, + Hooks: make(logrus.LevelHooks), + Level: logrus.DebugLevel, }, - Hooks: make(logrus.LevelHooks), - Level: logrus.DebugLevel, } } func New() Logger { return log } + +func (l *logger) SetLevel(level Level) { + l.Logger.SetLevel(logrus.Level(level)) +}