Documentation ¶
Overview ¶
零、设置分割错误日志
- 如果设置了分离错误日志,则会在目录文件生成2006_01_02的文件夹,日期为log文件的创建时间。
- 错误日志文件名会在基础文件名后加上_error后缀。
一、既不设置按日期分割也不设置按大小分割(默认)
- 空配置会在目录生成文件default.log(如果设置了日志文件名则为设置的文件名)
二、设置了按日期分割
- 其它为默认配置则会在目录生成文件2006_01_02.log(设置日志文件名无效)
三、设置了按大小分割
- 其它为默认配置则会在目录生成文件2006_01_02_150405.log(设置日志文件名无效)
四、其他
- 文件夹设置名称为log的创建时间而不加上最后修改时间是因为怕程序运行崩溃后,最后修改时间没有被添加。 这样在设置了最大保存天数的情况下,会不太好处理。
- 设置了最大保存天数后,会在程序启动时启动一个goroutine来删除过期的日志文件(24小时检查一次)。 若有不想被删除的日志文件,可以在文件名后加上keep,如:2006_01_02_150405_keep.log,或者 在文件夹名后加上keep,如:2006_01_02_keep。
Index ¶
Constants ¶
View Source
const ( PanicLevel = "panic" FatalLevel = "fatal" ErrorLevel = "error" WarnLevel = "warn" InfoLevel = "info" DebugLevel = "debug" TraceLevel = "trace" )
logrus level
View Source
const DefaultSavePath = "./logs"
Default log folder path.
After enabling the maximum retention days for logs, if the log folder path is not set, it defaults to this path.
Variables ¶
This section is empty.
Functions ¶
func DeleteOldLog ¶
Delete n days old logs, n equals 0 to delete all logs.
func InitGlobalLogger ¶
InitGlobalLogger initializes the global logger.The global logger is the default logger of logrus.
func PraseLevel ¶
panic,fatal,error,warn,info,debug,trace 默认info
Types ¶
type LogConfig ¶
type LogConfig struct { // Path for log storage. LogDir string // Log file name suffix LogFileNameSuffix string // Default log file name (ignored if split by date or size) DefaultLogName string // Separate error logs (for Error level and above) ErrSeparate bool // Exclude error logs from normal log file (when errors are separated) ErrNotInNormal bool // Split logs by date (cannot be used with size split) DateSplit bool // Disable file output for logs LogFileDisable bool // Disable console output for logs NoConsole bool // Disable timestamp in logs NoTimestamp bool // Timestamp format, default is 2006-01-02 15:04:05.000 TimestampFormat string // Show short file path in console output ShowShortFileInConsole bool // Show function name in console output ShowFuncInConsole bool // Disable caller information DisableCaller bool // Disable write buffer DisableWriterBuffer bool // Write buffer size, default is 4096 bytes WriterBufferSize int // Output in JSON format JSONFormat bool // Disable color output DisableColors bool // Disables the truncation of the level text to 4 characters. DisableLevelTruncation bool // PadLevelText Adds padding the level text so that all the levels // output at the same length PadLevelText is a superset of the DisableLevelTruncation option PadLevelText bool // Split logs by size in bytes (cannot be used with date split) MaxLogSize int64 // Maximum retention days for logs. After enabling this, if the log folder path is not set, it defaults to DefaultSavePath. // Please do not place other files in the log folder, otherwise they may be deleted. MaxKeepDays int // Log file extension (default is .log) LogExt string // Log level (panic, fatal, error, warn, info, debug, trace) LogLevel string // Time zone TimeLocation *time.Location // contains filtered or unexported fields }
func (*LogConfig) SetKeyValue ¶
SetKeyValue sets the key and value for appending to each log entry.
Click to show internal directories.
Click to hide internal directories.