Documentation ¶
Index ¶
Constants ¶
View Source
const ( // WriteSync 同步写 WriteSync = 1 // WriteAsync 异步写 WriteAsync = 2 // WriteFast 极速写(异步丢弃) WriteFast = 3 )
View Source
const ( // RollBySize 按大小分割文件 RollBySize = "size" // RollByTime 按时间分割文件 RollByTime = "time" )
文件滚动类型配置字段
View Source
const ( // TimeFormatMinute 分钟 TimeFormatMinute = "%Y%m%d%H%M" // TimeFormatHour 小时 TimeFormatHour = "%Y%m%d%H" // TimeFormatDay 天 TimeFormatDay = "%Y%m%d" // TimeFormatMonth 月 TimeFormatMonth = "%Y%m" // TimeFormatYear 年 TimeFormatYear = "%Y" )
常用时间格式
View Source
const ( // Minute 按分钟分割 Minute = "minute" // Hour 按小时分割 Hour = "hour" // Day 按天分割 Day = "day" // Month 按月分割 Month = "month" // Year 按年分割 Year = "year" )
View Source
const ( // OutputConsole 控制台输出日志 OutputConsole = "console" // OutputFile 文件输出日志 OutputFile = "file" // EncoderTypeConsole 日志输出格式:控制台 EncoderTypeConsole = "console" // EncoderTypeJson 日志输出格式:json EncoderTypeJson = "json" )
Variables ¶
View Source
var Levels = map[string]zapcore.Level{ "": zapcore.DebugLevel, "debug": zapcore.DebugLevel, "info": zapcore.InfoLevel, "warn": zapcore.WarnLevel, "error": zapcore.ErrorLevel, "fatal": zapcore.FatalLevel, }
Levels zapcore level
Functions ¶
This section is empty.
Types ¶
type FileConfig ¶
type FileConfig struct { // LogPath 日志路径 LogPath string `yaml:"log_path"` // Filename 日志文件名 Filename string `yaml:"filename"` // WriteMode 日志写入模式,1-同步,2-异步,3-极速(异步丢弃) WriteMode int `yaml:"write_mode"` // RollType 文件滚动类型,size-按大小分割文件,time-按时间分割文件,默认按大小分割 RollType string `yaml:"roll_type"` // MaxAge 日志最大保留时间, 天 MaxAge int `yaml:"max_age"` // MaxBackups 日志最大文件数 MaxBackups int `yaml:"max_backups"` // Compress 日志文件是否压缩 Compress bool `yaml:"compress"` // MaxSize 日志文件最大大小(单位MB) MaxSize int `yaml:"max_size"` // 以下参数按时间分割时才有效 // TimeUnit 按时间分割文件的时间单位 // 支持year/month/day/hour/minute, 默认为day TimeUnit TimeUnit `yaml:"time_unit"` }
FileConfig 日志文件的配置
type Logger ¶
type Logger interface { // Trace logs to TRACE log. Arguments are handled in the manner of fmt.Print. Trace(args ...interface{}) // Tracef logs to TRACE log. Arguments are handled in the manner of fmt.Printf. Tracef(format string, args ...interface{}) // Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Print. Debug(args ...interface{}) // Debugf logs to DEBUG log. Arguments are handled in the manner of fmt.Printf. Debugf(format string, args ...interface{}) // Info logs to INFO log. Arguments are handled in the manner of fmt.Print. Info(args ...interface{}) // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf. Infof(format string, args ...interface{}) // Warn logs to WARNING log. Arguments are handled in the manner of fmt.Print. Warn(args ...interface{}) // Warnf logs to WARNING log. Arguments are handled in the manner of fmt.Printf. Warnf(format string, args ...interface{}) // Error logs to ERROR log. Arguments are handled in the manner of fmt.Print. Error(args ...interface{}) // Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. Errorf(format string, args ...interface{}) // Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print. // all Fatal logs will exit with os.Exit(1). Fatal(args ...interface{}) // Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. // all Fatal logs will exit with os.Exit(1). Fatalf(format string, args ...interface{}) // Sync calls the underlying Core's Sync method, flushing any buffered log entries. // Applications should take care to call Sync before exiting Sync() error // WithFields set some custom key-value fields // Do not use log.WithFields("k", "v").WithFields("k1", "v1").Debug("hello") WithFields(fields ...string) *zap.Logger }
Logger 定义 logger 接口
func NewLogger ¶
func NewLogger(c *OutputConfig) Logger
NewLogger new a zap log, default callerSkip is 2
type OutputConfig ¶
type OutputConfig struct { // Writer 日志输出端 (console, file) Writer string // FileConfig 日志文件配置,如果 Writer 为 file 则该配置不能为空 FileConfig FileConfig `yaml:"file_config"` // Formatter 日志输出格式 (console, json) Formatter string // Level 日志级别 debug info error Level string // CallerSkip 控制 log 函数嵌套深度 CallerSkip int `yaml:"caller_skip"` }
OutputConfig log output: console file remote
Click to show internal directories.
Click to hide internal directories.