leobot

Simple Telegram Logging Bot
git clone git://bsandro.tech/leobot
Log | Files | Refs | README | LICENSE

log.go (640B)


      1 package tgbotapi
      2 
      3 import (
      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.
     13 type BotLogger interface {
     14 	Println(v ...interface{})
     15 	Printf(format string, v ...interface{})
     16 }
     17 
     18 var log BotLogger = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
     19 
     20 // SetLogger specifies the logger that the package should use.
     21 func SetLogger(logger BotLogger) error {
     22 	if logger == nil {
     23 		return errors.New("logger is nil")
     24 	}
     25 	log = logger
     26 	return nil
     27 }