Skip to content

orandin/lumberjackrus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

lumberjackrus | local filesystem hook for Logrus

Example

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/orandin/lumberjackrus"
)

func init() {
	logrus.SetFormatter(&logrus.TextFormatter{})
	logrus.SetLevel(logrus.DebugLevel)

	hook, err := lumberjackrus.NewHook(
		&lumberjackrus.LogFile{
			Filename:   "/tmp/general.log",
			MaxSize:    100,
			MaxBackups: 1,
			MaxAge:     1,
			Compress:   false,
			LocalTime:  false,
		},
		logrus.InfoLevel,
		&logrus.TextFormatter{},
		&lumberjackrus.LogFileOpts{
			logrus.InfoLevel: &lumberjackrus.LogFile{
				Filename: "/tmp/info.log",
			},
			logrus.ErrorLevel: &lumberjackrus.LogFile{
				Filename:   "/tmp/error.log",
				MaxSize:    100,   // optional
				MaxBackups: 1,     // optional
				MaxAge:     1,     // optional
				Compress:   false, // optional
				LocalTime:  false, // optional
			},
		},
	)

	if err != nil {
		panic(err)
	}

	logrus.AddHook(hook)
}

func main() {
	logrus.Debug("Debug message") // It is not written to a file (because debug level < minLevel)
	logrus.Info("Info message")   // Written in /tmp/info.log
	logrus.Warn("Warn message")   // Written in /tmp/general.log
	logrus.Error("Error message") // Written in /tmp/error.log
}

About

A local file system hook for sirupsen/logrus

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages