Documentation ¶
Overview ¶
Package log 模块名: 模块名 功能描述: 描述 作者: yr 2023/5/22 0022 21:49 最后更新: yr 2023/5/22 0022 21:49
Package log 模块名: 日志格式化 功能描述: 日志格式化 作者: yr 2024/3/1 0001 11:12 最后更新: yr 2024/3/1 0001 11:12
Package log 模块名: 日志接口定义 功能描述: 日志接口 作者: yr 2024/3/1 0001 11:12 最后更新: yr 2024/3/1 0001 11:12
Package log 模块名: 模块名 功能描述: 描述 作者: yr 2024/3/2 0002 18:57 最后更新: yr 2024/3/2 0002 18:57
Index ¶
Constants ¶
const ( ColorRed = "1;31m" // 红色 ColorGreen = "1;32m" // 绿色 ColorYellow = "1;33m" // 黄色 ColorBlue = "1;34m" // 蓝色 ColorMagenta = "1;35m" // 紫色 ColorCyan = "1;36m" // 天蓝色 ColorWhite = "1;37m" // 白色 ColorRedBg = "41;37m" // 红底白字 )
const ( PanicLevelStr = "panic" FatalLevelStr = "fatal" ErrorLevelStr = "error" WarnLevelStr = "warn" InfoLevelStr = "info" DebugLevelStr = "debug" TraceLevelStr = "trace" )
Variables ¶
var ( DefaultRotationTimeErr = errors.New("rotationTime must >= 1min and <= 24hour") DefaultLogLevelErr = errors.New("log level must <= 6") )
Functions ¶
Types ¶
type CallerHook ¶
type CallerHook struct{}
CallerHook 增加调用者信息的钩子(由于调用者被集成到了Format函数中,所以这里暂时废弃)
func (CallerHook) Levels ¶
func (CallerHook) Levels() []logrus.Level
type FormatFunction ¶ added in v1.0.4
type FormatFunction = logrus.LogFunction
type Formatter ¶
type Formatter struct { logrus.Formatter Mu *sync.Mutex // FieldsOrder - default: fields sorted alphabetically FieldsOrder []string // TimestampFormat - default: time.StampMilli = "2006-01-02 15:04:05.000" TimestampFormat string // HideKeys - show [fieldValue] instead of [fieldKey:fieldValue] HideKeys bool // Colors - enable colors, default is disable Colors bool // TrimMessages - trim whitespaces on messages TrimMessages bool // NoCaller - disable print caller info NoCaller bool // FullCaller - print full caller info FullCaller bool // CustomCallerFormatter - set custom formatter for caller info CustomCallerFormatter func(*runtime.Frame) string // contains filtered or unexported fields }
Formatter - logrus formatter, implements logrus.Formatter
func (*Formatter) Format ¶
Format a log entry (2006-01-02 15:04:05.000 [DEBUG] (test.go:5 func test) aaa=1 bbb=2 this is message)
func (*Formatter) SetCallerDisable ¶
SetCallerDisable 关闭调用者信息打印(默认开启)
func (*Formatter) SetFullCaller ¶
SetFullCaller 开启详细调用者信息打印(默认关闭)
func (*Formatter) SetTimestampFormat ¶
SetTimestampFormat 日期格式化样式(默认 2006-01-02 15:04:05.000)
type HookFunction ¶ added in v1.0.4
type ILogger ¶
func NewDefaultLogger ¶
func NewDefaultLogger(filePath, fileName string, maxAge, rotationTime time.Duration, level string, withCaller, fullCaller, withColors, openStdout bool) (ILogger, error)
NewDefaultLogger 创建一个通用日志对象 filePath 日志输出目录 fileName 日志文件名(最终文件名会是 filePath/fileName_20060102150405.log)(fileName为空且开启标准输出的情况下默认输出到stdout,否则无任何输出) maxAge 最大存放时间(过期会自动删除) rotationTime 自动切分间隔(到期日志自动切换新文件) level 日志级别(小于设置级别的信息都会被记录打印,设置级别如果超出限制,默认日志等级为error,取值为panic fatal error warn info debug trace) withCaller 是否需要调用者信息 fullCaller 如果需要打印调用者信息,那么这个参数可以设置调用者信息的详细程度 withColors 是否需要信息的颜色(基本上只能用于linux的前台打印) openStdout 是否开启标准输出(如果fileName为空,且openStdout未开启,那么将不会有任何日志信息被记录) TODO 支持远程日志钩子函数,可以将日志发送到远程的日志记录器上(这个函数需要go出去执行,不能阻塞)
type Level ¶
const ( // PanicLevel level, the highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = logrus.PanicLevel // FatalLevel level. Logs and then calls `Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel Level = logrus.FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel Level = logrus.ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel Level = logrus.WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel Level = logrus.InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel Level = logrus.DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel Level = logrus.TraceLevel )
These are the different logging levels. You can set the logging level to log on your instance of rusLogger, obtained with `logrus.New()`.
type Option ¶
type Option func(*Logger)
func WithFullCaller ¶
WithFullCaller sets print full caller info
func WithHook ¶
func WithHook(hook HookFunction) Option
func WithTimeFormat ¶
type ROption ¶
type ROption func(o *options)
func WithRotationTime ¶
WithRotationTime sets the Rotate rotation time.