logrus_lfshook

package module
v0.0.0-...-7b39b06 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2016 License: MIT Imports: 6 Imported by: 0

README

logrus-lfshook

local file log hook for logrus, support log segmentation by time or file size

install

go get "github.com/fanyang1988/logrus-lfshook"

usage

the hook create a gorountine, so it need close when app exit.

    import (
        "github.com/Sirupsen/logrus"
        "github.com/fanyang1988/logrus-lfshook"
    )

    func main() {
        // config for hook
        cfg := logrus_lfshook.HookConfig{}

        // add config for a log level
        cfg.AddLevel(
            logrus.InfoLevel, // log level
            "./info.log",     // file path for log
            3000,             // time for auto flush(ms)
            300)              // size for auto flush(kb)

        hook := logrus_lfshook.NewHook(cfg)

        // to close hook to flush before exit
        defer hook.Close()

        logrus.AddHook(hook)
        logrus.SetLevel(logrus.DebugLevel)
        logrus.WithField("c", i).Info("logs")
    }

TODO

  • auto flush by size
  • segmentation by time or file size

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnConfigLevel = errors.New("ErrUnConfigLevel")
)

Functions

func NewHook

func NewHook(cfg HookConfig) *hook

Types

type HookConfig

type HookConfig struct {
	FlushTime  int64 // ms
	FlushCount int64
	Levels     map[string]levelConfig
	// contains filtered or unexported fields
}

HookConfig config info for hook, can load as toml

func (*HookConfig) AddLevel

func (h *HookConfig) AddLevel(
	level Level,
	path string,
	time4seg int64,
	size4seg int64)

AddLevel add config info for a log level

func (*HookConfig) LoadFromToml

func (h *HookConfig) LoadFromToml(datas []byte) error

LoadFromToml load config info by "github.com/BurntSushi/toml"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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