telegram-bot-api/log.go

28 lines
640 B
Go
Raw Normal View History

2018-08-06 23:15:37 +02:00
package tgbotapi
import (
"errors"
stdlog "log"
"os"
2018-08-06 23:15:37 +02:00
)
2018-10-08 09:25:09 +02:00
// 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)
2018-08-06 23:15:37 +02:00
// SetLogger specifies the logger that the package should use.
2018-10-08 09:25:09 +02:00
func SetLogger(logger BotLogger) error {
if logger == nil {
2018-08-06 23:15:37 +02:00
return errors.New("logger is nil")
}
2018-10-08 09:25:09 +02:00
log = logger
2018-08-06 23:15:37 +02:00
return nil
}