nsqlogrus

package module
v0.0.0-...-8e00135 Latest Latest
Warning

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

Go to latest
Published: May 16, 2020 License: MIT Imports: 6 Imported by: 0

README

Nsq Hook for Logrus

Like https://github.com/sohlich/elogrus, but for nsq

Changelog

Usage

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/chennqqi/nsqlogrus"
	"github.com/nsqio/go-nsq"
)

func main() {
	log := logrus.New()
	config := nsq.NewConfig()
	client, err := nsq.NewProducer("127.0.0.1:4150", config)
	if err != nil {
		log.Panic(err)
	}
	
	//make sure all message flush
	defer client.Stop()
	
	hook, err := nsqlogrus.NewAsyncNsqHook(client, "localhost", "mylog", logrus.DebugLevel)
	if err != nil {
		log.Panic(err)
	}
	log.Hooks.Add(hook)

	log.WithFields(logrus.Fields{
		"name": "joe",
		"age":  42,
	}).Error("Hello world!")
}
Asynchronous hook
	...
	nsqlogrus.NewAsyncNsqHook(client, "localhost", "mylog", logrus.DebugLevel)
	...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NsqHook

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

NsqHook is a logrus hook for nsq

func NewAsyncNsqHook

func NewAsyncNsqHook(client *nsq.Producer, host, topic string, level logrus.Level) (*NsqHook, error)

NewAsyncNsqHook creates new hook with asynchronous log. client - nsq producer client host - host of system topic - name of nsqd level - log level index - name of the index in ElasticSearch

func NewNsqHook

func NewNsqHook(client *nsq.Producer, host, topic string, level logrus.Level) (*NsqHook, error)

NewNsqHook creates new hook. client - nsq producer client host - host of system topic - name of nsqd level - log level

func (*NsqHook) Cancel

func (hook *NsqHook) Cancel()

Cancel all calls to elastic

func (*NsqHook) Fire

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

Fire is required to implement Logrus hook

func (*NsqHook) Levels

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

Levels Required for logrus hook implementation

Jump to

Keyboard shortcuts

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