logx

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package lfshook is hook for sirupsen/logrus that used for writing the logs to local files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLog

func DefaultLog() *logrus.Logger

func InitLogWithFile

func InitLogWithFile(paths PathMap) (*logrus.Logger, error)

Types

type LfsHook

type LfsHook struct {
	FdMaxLen  int
	FdMaxSize int64
	// contains filtered or unexported fields
}

func NewLfsHook

func NewLfsHook(output interface{}, formatter logrus.Formatter, maxsz ...int64) *LfsHook

NewHook returns new LFS hook. Output can be a string, io.Writer, WriterMap or PathMap. If using io.Writer or WriterMap, user is responsible for closing the used io.Writer.

func (*LfsHook) Fire

func (hook *LfsHook) Fire(entry *logrus.Entry) error

Fire writes the log file to defined path or using the defined writer. User who run this function needs write permissions to the file or directory if the file does not yet exist.

func (*LfsHook) Levels

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

Levels returns configured log levels.

func (*LfsHook) SetDefaultPath

func (hook *LfsHook) SetDefaultPath(defaultPath string)

SetDefaultPath sets default path for levels that don't have any defined output path.

func (*LfsHook) SetDefaultWriter

func (hook *LfsHook) SetDefaultWriter(defaultWriter io.Writer)

SetDefaultWriter sets default writer for levels that don't have any defined writer.

func (*LfsHook) SetFormatter

func (hook *LfsHook) SetFormatter(formatter logrus.Formatter)

SetFormatter sets the format that will be used by hook. If using text formatter, this method will disable color output to make the log file more readable.

type PathMap

type PathMap map[logrus.Level]string

PathMap is map for mapping a log level to a file's path. Multiple levels may share a file, but multiple files may not be used for one level.

type WriterMap

type WriterMap map[logrus.Level]io.Writer

WriterMap is map for mapping a log level to an io.Writer. Multiple levels may share a writer, but multiple writers may not be used for one level.

Jump to

Keyboard shortcuts

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