ik5 / rotatefilehook

This is a logrus hook for rotating log files. This is basically a wrapper around the lumberjack library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RotateFileHook

This is a simple hook for logrus to write log files using https://github.com/natefinch/lumberjack

import (
  "github.com/ik5/rotatefilehook"
)

rotateFileHook, err := rotatefilehook.NewRotateFileHook(rotatefilehook.RotateFileConfig{
    Filename: "logfile.log",
    MaxSize: 5,
    MaxBackups: 7,
    MaxAge: 7,
    Level: logrus.LevelDebug,
    Formatter: logrus.TextFormatter,
    LocalTime: true,
    Compress: false,
})
if err != nil {
  panic(err)
}

log.Hooks.Add(rotateFileHook)

err = rotateFileHook.Rotate() // To force rotation
if err != nil {
  panic(err)
}
ezoic increase your site revenue

About

This is a logrus hook for rotating log files. This is basically a wrapper around the lumberjack library.

License:MIT License


Languages

Language:Go 100.0%