https://github.com/krasun/logrus2telegram
A Telegram bot hook for Logrus logging library in Go
https://github.com/krasun/logrus2telegram
go golang logging logrus logrus-go logrus-helper logrus-hook logrus-wrappers telegram-bot
Last synced: about 1 month ago
JSON representation
A Telegram bot hook for Logrus logging library in Go
- Host: GitHub
- URL: https://github.com/krasun/logrus2telegram
- Owner: krasun
- License: mit
- Created: 2021-12-19T17:05:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-09T12:45:21.000Z (over 3 years ago)
- Last Synced: 2025-04-19T11:23:29.413Z (about 1 month ago)
- Topics: go, golang, logging, logrus, logrus-go, logrus-helper, logrus-hook, logrus-wrappers, telegram-bot
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logrus2telegram
[](https://github.com/krasun/logrus2telegram/actions/workflows/build.yml)
[](https://codecov.io/gh/krasun/logrus2telegram)
[](https://goreportcard.com/report/github.com/krasun/logrus2telegram)
[](https://godoc.org/github.com/krasun/logrus2telegram)`logrus2telegram` is a Telegram bot hook for [Logrus logging library](https://github.com/sirupsen/logrus) in Go.
## Installation
As simple as:
```
go get github.com/krasun/logrus2telegram
```## Usage
```go
package mainimport (
log "github.com/sirupsen/logrus"
"github.com/krasun/logrus2telegram"
)func main() {
hook, err := logrus2telegram.NewHook(
,
[]int64{},
// 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)
```## Tests
To make sure that the code is fully tested and covered:
```
$ go test .
ok github.com/krasun/logrus2telegram 0.470s
```## Known Usages
...
## License
**logrus2telegram** is released under [the MIT license](LICENSE).