elogrus

package module
v3.0.0-...-1fa29e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2018 License: MIT Imports: 6 Imported by: 19

README

ElasticSearch Hook for Logrus

Elasticsearch version Elastic version Package URL
6.x 6.0 gopkg.in/sohlich/elogrus.v3
5.x 5.0 gopkg.in/sohlich/elogrus.v2
2.x 3.0 gopkg.in/sohlich/elogrus.v1

Changelog

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

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")
	...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCannotCreateIndex Fired if the index is not created
	ErrCannotCreateIndex = fmt.Errorf("Cannot create index")
)

Functions

This section is empty.

Types

type ElasticHook

type ElasticHook struct {
	// contains filtered or unexported fields
}

ElasticHook is a logrus hook for ElasticSearch

func NewAsyncElasticHook

func NewAsyncElasticHook(client *elastic.Client, host string, level logrus.Level, index string) (*ElasticHook, error)

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

func NewAsyncElasticHookWithFunc

func NewAsyncElasticHookWithFunc(client *elastic.Client, host string, level logrus.Level, indexFunc IndexNameFunc) (*ElasticHook, error)

NewAsyncElasticHookWithFunc creates new asynchronous hook with function that provides the index name. This is useful if the index name is somehow dynamic especially based on time. client - ElasticSearch client using gopkg.in/olivere/elastic.v5 host - host of system level - log level indexFunc - function providing the name of index

func NewElasticHook

func NewElasticHook(client *elastic.Client, host string, level logrus.Level, index string) (*ElasticHook, error)

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

func NewElasticHookWithFunc

func NewElasticHookWithFunc(client *elastic.Client, host string, level logrus.Level, indexFunc IndexNameFunc) (*ElasticHook, error)

NewElasticHookWithFunc creates new hook with function that provides the index name. This is useful if the index name is somehow dynamic especially based on time. client - ElasticSearch client using gopkg.in/olivere/elastic.v5 host - host of system level - log level indexFunc - function providing the name of index

func (*ElasticHook) Cancel

func (hook *ElasticHook) Cancel()

Cancel all calls to elastic

func (*ElasticHook) Fire

func (hook *ElasticHook) Fire(entry *logrus.Entry) error

Fire is required to implement Logrus hook

func (*ElasticHook) Levels

func (hook *ElasticHook) Levels() []logrus.Level

Levels Required for logrus hook implementation

type IndexNameFunc

type IndexNameFunc func() string

IndexNameFunc get index name

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL