Categorygithub.com/kitmartindev/elogrus
modulepackage
2.0.2+incompatible
Repository: https://github.com/kitmartindev/elogrus.git
Documentation: pkg.go.dev

# README

ElasticSearch Hook for Logrus :walrus:

Elasticsearch versionElastic version -Package URL
5.x5.0gopkg.in/sohlich/elogrus.v2
2.x3.0gopkg.in/sohlich/elogrus.v1

Usage

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!")
}

# Functions

NewElasticHook creates new hook client - ElasticSearch client using gopkg.in/olivere/elastic.v5 host - host of system level - log level index - name of the index in ElasticSearch.

# Variables

Fired if the index is not created.

# Structs

ElasticHook is a logrus hook for ElasticSearch.