logrus_kinesis

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2017 License: MIT Imports: 8 Imported by: 1

README

logrus_kinesis

Build Status Coverage Status codecov GoDoc

AWS Kinesis Hook for Logrus

Usage

import (
    "github.com/evalphobia/logrus_kinesis"
    "github.com/sirupsen/logrus"
)

func main() {
    hook, err := logrus_kinesis.New("my_stream", Config{
        AccessKey: "ABC", // AWS accessKeyId
        SecretKey: "XYZ", // AWS secretAccessKey
        Region:    "ap-northeast-1",
    })

    // set custom fire level
    hook.SetLevels([]logrus.Level{
        logrus.PanicLevel,
        logrus.ErrorLevel,
    })

    // ignore field
    hook.AddIgnore("context")

    // add custome filter
    hook.AddFilter("error", logrus_kinesis.FilterError)


    // send log with logrus
    logger := logrus.New()
    logger.Hooks.Add(hook)
    logger.WithFields(f).Error("my_message") // send log data to kinesis as JSON
}

Special fields

Some logrus fields have a special meaning in this hook.

message if message is not set, entry.Message is added to log data in "message" field.
stream_name stream_name is a custom stream name for Kinesis. If not set, defaultStreamName is used as stream name.
partition_key partition_key is a custom partition key for Kinesis. If not set, defaultStreamName or entry.Message is used as stream name.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AccessKey string
	SecretKey string
	Region    string
	Endpoint  string
}

Config has AWS settings.

func (Config) AWSConfig

func (c Config) AWSConfig() *aws.Config

AWSConfig creates *aws.Config object from the fields.

type KinesisHook

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

KinesisHook is logrus hook for AWS kinesis.

func New

func New(name string, conf Config) (*KinesisHook, error)

New returns initialized logrus hook for fluentd with persistent fluentd logger.

func NewWithAWSConfig

func NewWithAWSConfig(name string, conf *aws.Config) (*KinesisHook, error)

NewWithConfig returns initialized logrus hook for fluentd with persistent fluentd logger.

func (*KinesisHook) AddFilter

func (h *KinesisHook) AddFilter(name string, fn func(interface{}) interface{})

AddFilter adds a custom filter function.

func (*KinesisHook) AddIgnore

func (h *KinesisHook) AddIgnore(name string)

AddIgnore adds field name to ignore.

func (*KinesisHook) Async

func (h *KinesisHook) Async()

Async sets async flag and send log asynchroniously. If use this option, Fire() does not return error.

func (*KinesisHook) Fire

func (h *KinesisHook) Fire(entry *logrus.Entry) error

Fire is invoked by logrus and sends log to kinesis.

func (*KinesisHook) Levels

func (h *KinesisHook) Levels() []logrus.Level

Levels returns logging level to fire this hook.

func (*KinesisHook) SetLevels

func (h *KinesisHook) SetLevels(levels []logrus.Level)

SetLevels sets logging level to fire this hook.

func (*KinesisHook) SetPartitionKey

func (h *KinesisHook) SetPartitionKey(key string)

SetPartitionKey sets default partitionKey for kinesis.

Jump to

Keyboard shortcuts

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