log.go 640 B

123456789101112131415161718192021222324252627
  1. package tgbotapi
  2. import (
  3. "errors"
  4. stdlog "log"
  5. "os"
  6. )
  7. // BotLogger is an interface that represents the required methods to log data.
  8. //
  9. // Instead of requiring the standard logger, we can just specify the methods we
  10. // use and allow users to pass anything that implements these.
  11. type BotLogger interface {
  12. Println(v ...interface{})
  13. Printf(format string, v ...interface{})
  14. }
  15. var log BotLogger = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
  16. // SetLogger specifies the logger that the package should use.
  17. func SetLogger(logger BotLogger) error {
  18. if logger == nil {
  19. return errors.New("logger is nil")
  20. }
  21. log = logger
  22. return nil
  23. }