fluentd

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fluentd exposes a class that adheres to the logrus.Hook interface. Create it, then add it to an existing logger using the .AddHook method of a logrus.Logger

Example initialization:

```go
import (
	"github.com/usvc/go-log/pkg/logger"
	"github.com/usvc/go-log/pkg/hooks/fluentd"
	"github.com/usvc/go-log/pkg/constants"
)

// ...

logger := logger.New()
fluentHook := fluentd.NewHook(&fluenthook.HookConfig{
	Host:                    "localhost",
	Port:                    24224,
	InitializeRetryCount:    10,
	InitializeRetryInterval: time.Second * 1,
	Levels:                  constants.DefaultHookLevels,
	Tag:                     "tag",
}
logger.AddHook(fluentHook)
```

For the full guide visit https://gitlab.com/usvc/modules/go/log

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

Hook implements the logrus.Hook interface

func NewHook

func NewHook(
	config *HookConfig,
	logger ...Logger,
) *Hook

NewHook instantiates a new minimal fluentd hook given a configuration and an optional logger to use (if a logger is not provided, the in- built one will be used)

func (*Hook) Close

func (hook *Hook) Close()

Close closes the hook's fluentd instance

func (*Hook) Fire

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

Fire implements the logrus.Hook interface

func (*Hook) Levels

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

Levels implements the logrus.Hook interface

type HookConfig

type HookConfig struct {
	// Host contains the hostname of the fluentd service
	//
	// example: "fluentd.monitoring.svc.cluster.local"
	Host string

	// Port contains the port that the fluentd service
	// is listening on
	//
	// example: 24224
	Port int

	// InitializeRetryCount indicates how many times the
	// initialize() function should try to connect to the
	// fluentd service before it fails
	//
	// example: 10
	InitializeRetryCount int

	// InitializeRetryInterval indicates the duration in
	// between connection attempts to fluentd by initialize()
	//
	// example: 5 * time.Second
	InitializeRetryInterval time.Duration

	// Levels is an array of logrus levels that the hook
	// should be activated for
	//
	// example: []logrus.Level{logrus.TraceLevel}
	Levels []logrus.Level

	// Tag defines the base tag used to tag the log entries
	// sent to fluentd
	//
	// example: "application"
	Tag string
}

HookConfig stores the configuration for the Hook class and contains properties that will be used to initialise the Hook

func NewConfig added in v0.1.8

func NewConfig() *HookConfig

NewConfig returns a hook configuration with the default configuration

type Logger added in v0.1.5

type Logger interface {
	Trace(...interface{})
	Tracef(string, ...interface{})
	Debug(...interface{})
	Debugf(string, ...interface{})
	Info(...interface{})
	Infof(string, ...interface{})
	Warn(...interface{})
	Warnf(string, ...interface{})
	Error(...interface{})
	Errorf(string, ...interface{})
}

Jump to

Keyboard shortcuts

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