diff options
Diffstat (limited to 'vendor/github.com/nlopes/slack/logger.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/logger.go | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/vendor/github.com/nlopes/slack/logger.go b/vendor/github.com/nlopes/slack/logger.go index 501d1672..6a3533a9 100644 --- a/vendor/github.com/nlopes/slack/logger.go +++ b/vendor/github.com/nlopes/slack/logger.go @@ -2,52 +2,59 @@ package slack import ( "fmt" - "sync" ) -// SetLogger let's library users supply a logger, so that api debugging -// can be logged along with the application's debugging info. -func SetLogger(l logProvider) { - loggerMutex.Lock() - logger = ilogger{logProvider: l} - loggerMutex.Unlock() -} - -var ( - loggerMutex = new(sync.Mutex) - logger logInternal // A logger that can be set by consumers -) - -// logProvider is a logger interface compatible with both stdlib and some -// 3rd party loggers such as logrus. -type logProvider interface { +// logger is a logger interface compatible with both stdlib and some +// 3rd party loggers. +type logger interface { Output(int, string) error } -// logInternal represents the internal logging api we use. -type logInternal interface { +// ilogger represents the internal logging api we use. +type ilogger interface { + logger Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) - Output(int, string) error } -// ilogger implements the additional methods used by our internal logging. -type ilogger struct { - logProvider +type debug interface { + Debug() bool + + // Debugf print a formatted debug line. + Debugf(format string, v ...interface{}) + // Debugln print a debug line. + Debugln(v ...interface{}) +} + +// internalLog implements the additional methods used by our internal logging. +type internalLog struct { + logger } // Println replicates the behaviour of the standard logger. -func (t ilogger) Println(v ...interface{}) { +func (t internalLog) Println(v ...interface{}) { t.Output(2, fmt.Sprintln(v...)) } // Printf replicates the behaviour of the standard logger. -func (t ilogger) Printf(format string, v ...interface{}) { +func (t internalLog) Printf(format string, v ...interface{}) { t.Output(2, fmt.Sprintf(format, v...)) } // Print replicates the behaviour of the standard logger. -func (t ilogger) Print(v ...interface{}) { +func (t internalLog) Print(v ...interface{}) { t.Output(2, fmt.Sprint(v...)) } + +type discard struct{} + +func (t discard) Debug() bool { + return false +} + +// Debugf print a formatted debug line. +func (t discard) Debugf(format string, v ...interface{}) {} + +// Debugln print a debug line. +func (t discard) Debugln(v ...interface{}) {} |