Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

var (
log = logging.MustGetLogger("goesl")

log = logging.MustGetLogger("goesl")
customLog Logging
// Example format string. Everything except the message has a custom color
// which is dependent on the log level. Many fields have a custom output
// formatting too, eg. the time returns the hour down to the milli second.
Expand All @@ -24,27 +24,60 @@ var (
)

func Debug(message string, args ...interface{}) {
log.Debugf(message, args...)
if customLog == nil {
log.Debugf(message, args...)
} else {
customLog.Debugf(message, args...)
}
}

func Error(message string, args ...interface{}) {
log.Errorf(message, args...)
if customLog == nil {
log.Errorf(message, args...)
} else {
customLog.Errorf(message, args...)
}
}

func Notice(message string, args ...interface{}) {
log.Noticef(message, args...)
if customLog == nil {
log.Noticef(message, args...)
} else {
customLog.Noticef(message, args...)
}
}

func Info(message string, args ...interface{}) {
log.Infof(message, args...)
if customLog == nil {
log.Infof(message, args...)
} else {
customLog.Infof(message, args...)
}
}

func Warning(message string, args ...interface{}) {
log.Warningf(message, args...)
if customLog == nil {
log.Warningf(message, args...)
} else {
customLog.Warningf(message, args...)
}
}

type Logging interface {
Debugf(string, ...interface{})
Errorf(string, ...interface{})
Noticef(string, ...interface{})
Infof(string, ...interface{})
Warningf(string, ...interface{})
}

func init() {
backend := logging.NewLogBackend(os.Stderr, "", 0)
formatter := logging.NewBackendFormatter(backend, format)
logging.SetBackend(formatter)
customLog = nil
}

func SetCustomLogger(l Logging) {
customLog = l
}