telebot/middleware/logger.go
Кобелев Андрей Андреевич 1b497f2b9b init
2023-02-01 12:08:20 +03:00

28 lines
569 B
Go

package middleware
import (
"encoding/json"
"log"
tele "git.belvedersky.ru/common/telebot"
)
// Logger returns a middleware that logs incoming updates.
// If no custom logger provided, log.Default() will be used.
func Logger(logger ...*log.Logger) tele.MiddlewareFunc {
var l *log.Logger
if len(logger) > 0 {
l = logger[0]
} else {
l = log.Default()
}
return func(next tele.HandlerFunc) tele.HandlerFunc {
return func(c tele.Context) error {
data, _ := json.MarshalIndent(c.Update(), "", " ")
l.Println(string(data))
return next(c)
}
}
}