An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          


Logrus + Loki = ❤️


A Loki hook for Logrus

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/yukitsune/lokirus/go.yml?branch=main)](https://github.com/YuKitsune/lokirus/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/yukitsune/lokirus)](https://goreportcard.com/report/github.com/yukitsune/lokirus)
[![License](https://img.shields.io/github/license/YuKitsune/lokirus)](https://github.com/YuKitsune/lokirus/blob/main/LICENSE)
[![Latest Release](https://img.shields.io/github/v/release/YuKitsune/lokirus?include_prereleases)](https://github.com/YuKitsune/lokirus/releases)
[![PkgGoDev](https://pkg.go.dev/badge/mod/github.com/yukitsune/lokirus)](https://pkg.go.dev/mod/github.com/yukitsune/lokirus)


# Installation

```sh
go get github.com/yukitsune/lokirus
```

# Usage

```go
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")
}
```

# 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**!