logrus2telegram
is a Telegram bot hook for Logrus logging library in Go.
As simple as:
go get github.com/krasun/logrus2telegram
package main
import (
log "github.com/sirupsen/logrus"
"github.com/krasun/logrus2telegram"
)
func main() {
hook, err := logrus2telegram.NewHook(
<token>,
[]int64{<chat identifier>},
// the levels of messages sent to Telegram
// default: []log.Level{log.ErrorLevel, log.FatalLevel, log.PanicLevel, log.WarnLevel, log.InfoLevel} InfoLevel}
logrus2telegram.Levels(log.AllLevels),
// the levels of messages sent to Telegram with notifications
// default: []log.Level{log.ErrorLevel, log.FatalLevel, log.PanicLevel, log.WarnLevel, log.InfoLevel}
logrus2telegram.NotifyOn([]log.Level{log.PanicLevel, log.FatalLevel, log.ErrorLevel, log.InfoLevel}),
// default: 3 * time.second
logrus2telegram.RequestTimeout(10*time.Second),
// default: entry.String() time="2021-12-22T14:48:56+02:00" level=debug msg="example"
logrus2telegram.Format(func(e *log.Entry) (string, error) {
return fmt.Sprintf("%s %s", strings.ToUpper(e.Level.String()), e.Message), nil
}),
)
if err != nil {
// ...
}
log.AddHook(hook)
To make sure that the code is fully tested and covered:
$ go test .
ok github.com/krasun/logrus2telegram 0.470s
...
logrus2telegram is released under the MIT license.