all repos — telegram-bot-api @ a0a678302e8953531aa87a6a7e97a395c8954ada

Golang bindings for the Telegram Bot API

log.go (view raw)

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