A number of small improvements.
This commit is contained in:
parent
5f38203a15
commit
b6441c36ee
4 changed files with 38 additions and 11 deletions
17
log.go
17
log.go
|
@ -6,13 +6,22 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
var log = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
|
||||
// BotLogger is an interface that represents the required methods to log data.
|
||||
//
|
||||
// Instead of requiring the standard logger, we can just specify the methods we
|
||||
// use and allow users to pass anything that implements these.
|
||||
type BotLogger interface {
|
||||
Println(v ...interface{})
|
||||
Printf(format string, v ...interface{})
|
||||
}
|
||||
|
||||
var log BotLogger = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
|
||||
|
||||
// SetLogger specifies the logger that the package should use.
|
||||
func SetLogger(newLog *stdlog.Logger) error {
|
||||
if newLog == nil {
|
||||
func SetLogger(logger BotLogger) error {
|
||||
if logger == nil {
|
||||
return errors.New("logger is nil")
|
||||
}
|
||||
log = newLog
|
||||
log = logger
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue