Categorygithub.com/fossas/elogrus
modulepackage
1.0.0
Repository: https://github.com/fossas/elogrus.git
Documentation: pkg.go.dev

# README

ElasticSearch Hook for Logrus :walrus:

Releases

Notice that the master branch always refers to the latest version of Elastic. If you want to use stable versions of elogus, you should use the packages released via gopkg.in.

Here's the version matrix:

ElasticSearch versionElastic versionPackage URLRemarks
7.x7.0gopkg.in/sohlich/elogrus.v7Use Go modules.
6.x6.0gopkg.in/sohlich/elogrus.v3Actively maintained.
5.x5.0gopkg.in/sohlich/elogrus.v2Actively maintained.
2.x3.0gopkg.in/sohlich/elogrus.v1Deprecated. Please update.

For elastic search 7.x

# We name v7 to align with elastic v7
go get gopkg.in/sohlich/elogrus.v7
go get github.com/olivere/elastic/v7

For elastic search 6.x

go get gopkg.in/sohlich/elogrus.v3
go get github.com/olivere/elastic

For elastic search 5.x

go get gopkg.in/sohlich/elogrus.v2
go get gopkg.in/olivere/elastic.v5

Changelog

  • elastic 7.x support (currently in master)

Usage

package main

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

func main() {
	log := logrus.New()
	client, err := elastic.NewClient(elastic.SetURL("http://localhost:9200"))
	if err != nil {
		log.Panic(err)
	}
	hook, err := elogrus.NewAsyncElasticHook(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")
	...

# Functions

NewAsyncElasticHook creates new hook with asynchronous log.
NewAsyncElasticHookWithFunc creates new asynchronous hook with function that provides the index name.
NewBulkProcessorElasticHook creates new hook that uses a bulk processor for indexing.
NewBulkProcessorElasticHookWithFunc creates new hook with function that provides the index name.
NewElasticHook creates new hook.
NewElasticHookWithFunc creates new hook with function that provides the index name.

# Variables

ErrCannotCreateIndex Fired if the index is not created.

# Structs

ElasticHook is a logrus hook for ElasticSearch.
No description provided by the author

# Type aliases

IndexNameFunc get index name.
MessageTransformer transforms the content that is sent to elasticsearch.