2018-08-06 23:15:37 +02:00
|
|
|
package tgbotapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
stdlog "log"
|
2018-09-22 03:20:28 +02:00
|
|
|
"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
|
|
|
|
2018-09-22 03:20:28 +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
|
|
|
|
}
|