go get github.com/yukitsune/lokirus
package main
func 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") // Optional
hook := 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")
}
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!