rotatefilehook

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: MIT Imports: 2 Imported by: 0

README

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,
})
if err != nil {
  panic(err)
}

log.Hooks.Add(rotateFileHook)

err = rotateFileHook.Rotate() // To force rotation
if err != nil {
  panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RotateFileConfig

type RotateFileConfig struct {
	Filename   string
	MaxSize    int
	MaxBackups int
	MaxAge     int
	Level      logrus.Level
	Formatter  logrus.Formatter
	LocalTime  bool
	Compress   bool
}

RotateFileConfig holds basic information for using lumberjack and logrus hooks

type RotateFileHook

type RotateFileHook struct {
	Config    RotateFileConfig
	LogWriter *lumberjack.Logger
}

RotateFileHook holds hook information for logrus

func NewRotateFileHook

func NewRotateFileHook(config RotateFileConfig) (*RotateFileHook, error)

NewRotateFileHook initialize a new logrus.Hook or return an error

func (*RotateFileHook) Fire

func (hook *RotateFileHook) Fire(entry *logrus.Entry) (err error)

Fire implements the Fire interface method of logrus Hook

func (*RotateFileHook) Levels

func (hook *RotateFileHook) Levels() []logrus.Level

Levels implements the Levels interface method of logrus Hook

func (*RotateFileHook) Rotate

func (hook *RotateFileHook) Rotate() error

Rotate by request a log file (calling of SIGHUP for example)

Jump to

Keyboard shortcuts

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