ElasticSearch Hook for Logrus ![:walrus: :walrus:](https://camo.githubusercontent.com/cad5cef19f4709026d903572dfb5fe5a75d090d95dd822ddef499e131e63337a/687474703a2f2f692e696d6775722e636f6d2f68546556776d4a2e706e67)
Elasticsearch version | Elastic version - | Package URL |
---|---|---|
5.x | 5.0 | gopkg.in/sohlich/elogrus.v2 |
2.x | 3.0 | gopkg.in/sohlich/elogrus.v1 |
v2.1 - Added support for async hook
go get gopkg.in/sohlich/elogrus.v2
package main
import (
"github.com/sirupsen/logrus"
"gopkg.in/sohlich/elogrus.v2"
"gopkg.in/olivere/elastic.v5"
)
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!")
}
...
elogrus.NewAsyncElasticHook(client, "localhost", logrus.DebugLevel, "mylog")
...