Skip to content

YuKitsune/lokirus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7ec028a · Jan 21, 2023

History

31 Commits
May 6, 2022
May 27, 2022
May 6, 2022
May 4, 2022
May 4, 2022
Jan 21, 2023
May 6, 2022
May 6, 2022
May 5, 2022
May 27, 2022
May 27, 2022
May 27, 2022

Repository files navigation

Logrus + Loki = ❤️

A Loki hook for Logrus

GitHub Workflow Status Go Report Card License Latest Release PkgGoDev

Installation

go get github.com/yukitsune/lokirus

Usage

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!