xlogrus

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 12 Imported by: 0

README

xlogrus

Dependencies

  • github.com/Aoi-hosizora/ahlib
  • github.com/sirupsen/logrus
  • github.com/ah-forklib/lumberjack (gopkg.in/natefinch/lumberjack.v2)
  • github.com/ah-forklib/rotatelogs (github.com/lestrrat-go/file-rotatelogs)
  • github.com/ah-forklib/strftime (github.com/lestrrat-go/strftime)

Documents

Functions
Types
  • type SimpleFormatter struct
  • type RotateFileConfig struct
  • type RotateFileHook struct
  • type RotateLogConfig struct
  • type RotateLogHook struct
Variables
  • None
Constants
  • None
Functions
  • func NewRotateFileHook(config *RotateFileConfig) logrus.Hook
  • func NewRotateLogHook(config *RotateLogConfig) logrus.Hook
Methods
  • func (s *SimpleFormatter) Format(entry *logrus.Entry) ([]byte, error)
  • func (r *RotateFileHook) Fire(entry *logrus.Entry) error
  • func (r *RotateLogHook) Fire(entry *logrus.Entry) error

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRotateFileHook

func NewRotateFileHook(config *RotateFileConfig) logrus.Hook

NewRotateFileHook creates a RotateFileHook as logrus.Hook with RotateFileConfig.

func NewRotateLogHook

func NewRotateLogHook(config *RotateLogConfig) logrus.Hook

NewRotateLogHook creates a RotateLogHook as logrus.Hook with RotateLogConfig. Example:

hook := NewRotateLogHook(&RotateLogConfig{
	Filename:         "console",
	FilenameTimePart: ".%Y%m%d.log",
	LinkFileName:     "console.curr.log",
	Level:            logrus.WarnLevel,
	Formatter:        &logrus.JSONFormatter{TimestampFormat: time.RFC3339},
	MaxAge:           time.Hour * 24 * 30,
	MaxSize:          100,
	RotationTime:     time.Hour * 24,
	LocalTime:        false,
	ForceNewFile:     false,
})
logger.AddHook(hook)

Types

type RotateFileConfig

type RotateFileConfig struct {
	// Filename represents the log filename, with filepath, filename and extension, required.
	Filename string

	// Level represents the lowest log level, defaults to logrus.PanicLevel.
	Level logrus.Level

	// Formatter represents the logger formatter, defaults to logrus.JSONFormatter.
	Formatter logrus.Formatter

	// MaxAge represents the max day counts of the file, defaults not to remove old logs.
	MaxAge int

	// MaxSize represents the max size in MB of the file, defaults to 100MB.
	MaxSize int

	// LocalTime represents the switcher for local or UTC time, defaults to use UTC time.
	LocalTime bool

	// Compress represents the switcher of compression, defaults not to perform compression.
	Compress bool
}

RotateFileConfig represents RotateFileHook's config.

type RotateFileHook

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

RotateFileHook represents a logrus hook for writing logs into a single file. Example:

hook := NewRotateFileHook(&RotateFileConfig{
	Filename:  "console.log",
	Level:     logrus.WarnLevel,
	Formatter: &logrus.JSONFormatter{TimestampFormat: time.RFC3339},
	MaxAge:    30,
	MaxSize:   100,
	LocalTime: false,
	Compress:  true,
})
logger.AddHook(hook)

func (*RotateFileHook) Fire

func (r *RotateFileHook) Fire(entry *logrus.Entry) error

Fire writes logrus.Entry data to io.Writer, this implements logrus.Hook.

func (*RotateFileHook) Levels

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

type RotateLogConfig

type RotateLogConfig struct {
	// Filename represents the log filename without time part and extension, required.
	Filename string

	// FilenameTimePart represents time part after filename, defaults to ".%Y%m%d.log". See strftime.New.
	FilenameTimePart string

	// LinkFileName represents the symbolic link filename, defaults to "", no link will be written.
	LinkFileName string

	// Level represents the lowest log level, defaults to logrus.PanicLevel.
	Level logrus.Level

	// Formatter represents the logger formatter, defaults to logrus.JSONFormatter.
	Formatter logrus.Formatter

	// MaxAge represents the max duration of the file, defaults to one week.
	MaxAge time.Duration

	// MaxSize represents the max size in MB of the file, defaults to no limit.
	MaxSize int

	// RotationTime represents the rotation duration of the file, defaults to one day.
	RotationTime time.Duration

	// LocalTime represents the switcher for local or UTC time, defaults to use UTC time.
	LocalTime bool

	// ForceNewFile represents the switcher for forcing to save to new file, defaults to false.
	ForceNewFile bool
}

RotateLogConfig represents RotateLogHook's config.

type RotateLogHook

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

RotateLogHook represents a logrus hook for writing logs into files splitting by time.

func (*RotateLogHook) Fire

func (r *RotateLogHook) Fire(entry *logrus.Entry) error

Fire writes logrus.Entry data to io.Writer, this implements logrus.Hook.

func (*RotateLogHook) Levels

func (r *RotateLogHook) Levels() []logrus.Level

type SimpleFormatter added in v1.5.0

type SimpleFormatter struct {
	// TimestampFormat represents the time format, uses time.RFC3339 as default.
	TimestampFormat string

	// RuntimeCaller represents the caller prettifier, uses function and filename directly as default.
	RuntimeCaller func(*runtime.Frame) (function string, file string)

	// DisableColor represents the switcher for color, uses false (use color) as default.
	DisableColor bool
	// contains filtered or unexported fields
}

SimpleFormatter represents a simple formatter for logrus.Logger, it only formats level, time, caller and message information in colored, and the logrus.Fields data is not be logged like logrus.TextFormatter does.

func (*SimpleFormatter) Format added in v1.5.0

func (s *SimpleFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format renders a single log entry, this method implements logrus.Formatter.

Jump to

Keyboard shortcuts

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