Skip to content

markdicksonjr/elogrus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElasticSearch Hook for Logrus :walrus:

Elasticsearch version Elastic version Package URL Remarks
7.x 7.0 github.com/sohlich/elogrus/v7 Use Go modules.
6.x 6.0 gopkg.in/sohlich/elogrus.v3 Actively maintained.
5.x 5.0 gopkg.in/sohlich/elogrus.v2 Actively maintained.
2.x 3.0 gopkg.in/sohlich/elogrus.v1 Deprecated. Please update.

Changelog

  • elastic 7.x support (currently in master)

Import

go get gopkg.in/sohlich/elogrus.v3

Usage

package main

import (
	"github.com/sirupsen/logrus.v3"
	"gopkg.in/sohlich/elogrus"
	"gopkg.in/olivere/elastic"
)


func main() {
	log := logrus.New()
	client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200"))
	if err != nil {
		log.Panic(err)
	}	
	hook, err := elogrus.NewElasticHook(client, "localhost", logrus.DebugLevel, "mylog")
	if err != nil {
		log.Panic(err)
	}	
	log.Hooks.Add(hook)

	log.WithFields(logrus.Fields{
		"name": "joe",
		"age":  42,
	}).Error("Hello world!")
}

Asynchronous hook

	...
	elogrus.NewAsyncElasticHook(client, "localhost", logrus.DebugLevel, "mylog")
	...

About

Logrus Hook for ElasticSearch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%