logx

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Trace = "trace"
	Debug = "debug"
	Info  = "info"
	Error = "error"
	Fatal = "fatal"
	Panic = "panic"
)

日志级别

View Source
const (
	TimeFormat = "2006-01-02 15:04:05.999999"
)

Variables

This section is empty.

Functions

func InitLogger

func InitLogger()

初始化日志

func LoggerToFile

func LoggerToFile() gin.HandlerFunc

gin框架生成日志Handler

Types

type Config

type Config struct {
	LogDir     string `json:"logDir" yaml:"logDir"  default:"temp/log"`  // 日志保存文件夹
	LogName    string `json:"logName" yaml:"logName" default:"app"`      // 日志文件名
	LogLevel   string `json:"logLevel" yaml:"logLevel" default:"debug"`  // 日志级别
	LogSize    int    `json:"logSize" yaml:"logSize" default:"100"`      // 日志大小(单位:mb)
	LogAge     int    `json:"logAge" yaml:"logAge" default:"1"`          // 日志保留天数(单位:天)
	LogBackups int    `json:"logBackups" yaml:"logBackups" default:"10"` // 日志备份数
}

日志配置

var CONFIG *Config

type LfsHook

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

LfsHook is a hook to handle writing to local log files.

func NewHook

func NewHook(output interface{}, formatter logrus.Formatter) *LfsHook

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

writes the log file to defined path or using the defined writer. User who run this function needs to 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)

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

func (*LfsHook) SetDefaultWriter

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

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

func (*LfsHook) SetFormatter

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

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 LogFormatter

type LogFormatter struct {
	TimeFormat string
}

func (*LogFormatter) Format

func (f *LogFormatter) Format(entry *logrus.Entry) ([]byte, error)

日志格式化

type PathMap

type PathMap map[logrus.Level]string

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

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