Skip to content
forked from sohlich/elogrus

Logrus Hook for ElasticSearch

License

Notifications You must be signed in to change notification settings

meateam/elogrus

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElasticSearch Hook for Logrus :walrus:

Elasticsearch version Elastic version Package URL
7.x 7.0 github.com/meateam/elogrus.v4
6.x 6.0 github.com/meateam/elogrus.v3
5.x 5.0 github.com/meateam/elogrus.v2
2.x 3.0 github.com/meateam/elogrus.v1

Changelog

  • elastic 7.x support (currently in master)
  • elastic 6.x support (in v3)
  • v2.1 - Added support for async hook

Import

go get github.com/meateam/elogrus.v4

Usage

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/meateam/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")
	...