logrushook

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 8 Imported by: 0

README

logrus-hook

Go logrus hooks.

go get github.com/zhangjie2012/logrus-hook

Redis LIST

log write(RPUSH) to redis LIST.

option := RedisOption{
    Addr:     "localhost:6379",
    Password: "",
    DB:       0,
    Key:      "logrusredis.hook",
}
hook, _ := NewRedisHook("application_name", &option, nil)
logrus.AddHook(hook)

Customize

If you want customize inserted redis bs, you can customize a LogWashFunc, checkout redishook_test.go file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLogWashFunc

func DefaultLogWashFunc(appName string, t time.Time, metadata logrus.Fields, caller *runtime.Frame, level logrus.Level, message string) []byte

DefaultLogWashFunc log filter and serialization

  • use msgpack serialize log
  • level > 'DEBUG'
  • set current instance ip

Types

type DefaultLogS

type DefaultLogS struct {
	AppName  string        `msgpack:"@appname"`
	Time     time.Time     `msgpack:"@time"`
	MetaData logrus.Fields `msgpack:"@metadata"` // map[string]interface{}
	Ip       string        `msgpack:"@ip"`
	Level    string        `msgpack:"@level"`
	Caller   string        `msgpack:"@caller"`
	Message  string        `msgpack:"@message"`
}

type LogWashFunc

type LogWashFunc func(appName string, t time.Time, metadata logrus.Fields, caller *runtime.Frame, level logrus.Level, message string) []byte

LogWashFunc log struct to bytes

type RedisHook

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

func NewRedisHook

func NewRedisHook(appName string, option *RedisOption, logWashFunc LogWashFunc) (*RedisHook, error)

func (*RedisHook) Fire

func (h *RedisHook) Fire(e *logrus.Entry) (err error)

func (*RedisHook) Levels

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

type RedisOption

type RedisOption struct {
	Addr     string
	Password string
	DB       int
	Key      string
}

Jump to

Keyboard shortcuts

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