Browse Source

logger: add level support

Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
bboozzoo/golang
Maciek Borzecki 7 years ago
parent
commit
322fb34aea
2 changed files with 30 additions and 7 deletions
  1. +13
    -0
      logger/logger.go
  2. +17
    -7
      logger/logrus.go

+ 13
- 0
logger/logger.go View File

@ -35,4 +35,17 @@ type Logger interface {
Print(args ...interface{}) Print(args ...interface{})
Printf(format string, args ...interface{}) Printf(format string, args ...interface{})
Println(args ...interface{}) Println(args ...interface{})
SetLevel(level Level)
} }
type Level int
const (
PanicLevel Level = iota
FatalLevel
ErrorLevel
WarnLevel
InfoLevel
DebugLevel
)

+ 17
- 7
logger/logrus.go View File

@ -17,19 +17,29 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
) )
var log *logrus.Logger
type logger struct {
logrus.Logger
}
var log *logger
func init() { 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 { func New() Logger {
return log return log
} }
func (l *logger) SetLevel(level Level) {
l.Logger.SetLevel(logrus.Level(level))
}

Loading…
Cancel
Save