logrusfluent

package module
v0.0.0-...-0265db5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: MIT Imports: 3 Imported by: 0

README

logrus-fluent-hook

Fluent Hooks for Logrus

This is a hook to send the log to fluentd.

Usage

import (
	log "github.com/Sirupsen/logrus"
	"github.com/fluent/fluent-logger-golang/fluent"
	"github.com/mnrtks/logrusfluent"
)

func main() {
	fluentConf := fluent.Config{}
	hook, err := logrusfluent.NewFluentHook(fluentConf)
	if err == nil {
		hook.DefaultTag = "logrusfluent"
		log.AddHook(hook)
	}

	log.WithFields(log.Fields{
		"tag":    "hoge",
		"animal": "walrus",
		"size":   10,
	}).Info("A group of walrus emerges from the ocean")

	// The default tag is used if you do not specify a tag.
	log.WithFields(log.Fields{
		"omg":    true,
		"number": 122,
	}).Warn("The group's number increased tremendously!")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FluentHook

type FluentHook struct {
	Fluent     *fluent.Fluent
	DefaultTag string
	// contains filtered or unexported fields
}

FluentHook to send logs via fluentd.

func NewFluentHook

func NewFluentHook(config fluent.Config, fieldSizeLimit int) (*FluentHook, error)

NewFluentHook creates a new hook to send to fluentd.

func (*FluentHook) Fire

func (f *FluentHook) Fire(entry *logrus.Entry) error

Fire implements logrus.Hook interface Fire method.

func (*FluentHook) Levels

func (f *FluentHook) Levels() []logrus.Level

Levels implements logrus.Hook interface Levels method.

Jump to

Keyboard shortcuts

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