https://github.com/yukitsune/lokirus
A Loki hook for Logrus
https://github.com/yukitsune/lokirus
logrus logrus-hook loki
Last synced: 3 days ago
JSON representation
A Loki hook for Logrus
- Host: GitHub
- URL: https://github.com/yukitsune/lokirus
- Owner: YuKitsune
- License: mit
- Created: 2022-05-04T11:48:38.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-21T10:35:24.000Z (over 2 years ago)
- Last Synced: 2025-10-11T20:46:49.354Z (3 days ago)
- Topics: logrus, logrus-hook, loki
- Language: Go
- Homepage:
- Size: 842 KB
- Stars: 20
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Logrus + Loki = ❤️
A Loki hook for Logrus[](https://github.com/YuKitsune/lokirus/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/yukitsune/lokirus)
[](https://github.com/YuKitsune/lokirus/blob/main/LICENSE)
[](https://github.com/YuKitsune/lokirus/releases)
[](https://pkg.go.dev/mod/github.com/yukitsune/lokirus)
![]()
# Installation
```sh
go get github.com/yukitsune/lokirus
```# Usage
```go
package mainfunc main() {
// Configure the Loki hook
opts := lokirus.NewLokiHookOptions().
// Grafana doesn't have a "panic" level, but it does have a "critical" level
// https://grafana.com/docs/grafana/latest/explore/logs-integration/
WithLevelMap(lokirus.LevelMap{logrus.PanicLevel: "critical"}).
WithFormatter(&logrus.JSONFormatter{}).
WithStaticLabels(lokirus.Labels{
"app": "example",
"environment": "development",
}).
WithBasicAuth("admin", "secretpassword") // Optionalhook := lokirus.NewLokiHookWithOpts(
"http://localhost:3100",
opts,
logrus.InfoLevel,
logrus.WarnLevel,
logrus.ErrorLevel,
logrus.FatalLevel)// Configure the logger
logger := logrus.New()
logger.AddHook(hook)// Log all the things!
logger.WithField("fizz", "buzz").Warnln("warning")
}
```# Contributing
Contributions are what make the open source community such an amazing place to be, learn, inspire, and create.
Any contributions you make are **greatly appreciated**!