Documentation ¶
Index ¶
- Constants
- Variables
- func Default(level logger.LogLevel) logger.Interface
- func Error(template string, args ...interface{})
- func ErrorF(c *gin.Context, template string, args ...interface{})
- func ErrorLogId(logId, template string, args ...interface{})
- func GetRequestIdKey(c *gin.Context) (requestId string)
- func GetWriteSyncer(file string, lc *Config) zapcore.WriteSyncer
- func Info(template string, args ...interface{})
- func InfoApi(c *gin.Context, template string, args ...interface{})
- func InfoDB(c *gin.Context, template string, args ...interface{})
- func InfoF(c *gin.Context, template string, args ...interface{})
- func InfoLogId(logId, template string, args ...interface{})
- func InfoSdk(c *gin.Context, template string, args ...interface{})
- func InitLog(options *Config)
- func String(key string, value interface{}) zap.Field
- func Warn(template string, args ...interface{})
- func WarnF(c *gin.Context, title string, template string, args ...interface{})
- func WarnLogId(logId, template string, args ...interface{})
- type Config
- type Field
- type LogContext
- func (ctx *LogContext) ErrorF(template string, args ...interface{})
- func (ctx *LogContext) Field(key string, value interface{}) Field
- func (ctx *LogContext) GetClientIP() string
- func (ctx *LogContext) GetLogId() string
- func (ctx *LogContext) InfoF(template string, args ...interface{})
- func (ctx *LogContext) WarnF(template string, args ...interface{})
- type LogOptionFunc
- func SetLogAppMode(appMode string) LogOptionFunc
- func SetLogAppName(appName string) LogOptionFunc
- func SetLogChildPath(childPath string) LogOptionFunc
- func SetLogMaxAge(maxAge time.Duration) LogOptionFunc
- func SetLogMaxSize(size int64) LogOptionFunc
- func SetLogPath(logPath string) LogOptionFunc
- func SetLogType(logType string) LogOptionFunc
- func SetNoBuffWriter() LogOptionFunc
- func SetRotationCount(n uint) LogOptionFunc
- func SetRotationTime(rotationTime time.Duration) LogOptionFunc
- type LoggerContext
Constants ¶
View Source
const ( LevelInfo = "info" LevelWarn = "warn" LevelError = "error" MessageType = "message_type" //日志类型 XtraceKey = "trace_id" //外部链路ID RequestIdKey = "request_id" //链路ID TimeFormat = "2006-01-02 15:04:05" //默认时间 )
Variables ¶
View Source
var ( HeaderAppName = "app-name" KeyPath = "path" KeyTitle = "title" KeyOriginAppName = "origin_app_name" DefaultAppName = "app" // 默认应用名称 DefaultAppMode = "dev" // 默认应用环境 DefaultRunMode = "debug" // 默认运行环境 DefaultAppVersion = "1.0.0" // 默认版本 DefaultLogType = "file" // 默认日志类型 DefaultLogPath = "/home/logs/app/" // 默认文件目录 DefaultChildPath = "/file-%s.log" // 默认子目录 DefaultRotationSize = 32 * 1024 * 1024 // 默认大小为32M DefaultRotationCount = 0 // 默认不限制 DefaultRotationTime = 24 * time.Hour // 默认每天轮转一次 DefaultNoBuffWrite = false // 不不开启无缓冲写入 DefaultMaxAge = 90 * 24 * time.Hour // 默认保留90天 DefaultTraceType = "zipkin" //记录类型 zipkin 和 jaeger DefaultTraceAddr = "" DefaultTraceMod float64 = 0 )
View Source
var ( Sugar *zap.Logger DefaultConfig = &Config{ AppName: DefaultAppName, AppMode: DefaultAppMode, LogType: DefaultLogType, LogPath: DefaultLogPath, ChildPath: DefaultChildPath, RotationSize: int64(DefaultRotationSize), RotationCount: uint(DefaultRotationCount), NoBuffWrite: DefaultNoBuffWrite, RotationTime: DefaultRotationTime, MaxAge: DefaultMaxAge, } )
Functions ¶
func ErrorLogId ¶
func ErrorLogId(logId, template string, args ...interface{})
func GetRequestIdKey ¶
GetRequestIdKey 获取链路ID
func GetWriteSyncer ¶
func GetWriteSyncer(file string, lc *Config) zapcore.WriteSyncer
GetWriteSyncer 按天切割按大小切割 filename 文件名 RotationSize 每个文件的大小 MaxAge 文件最大保留天数 RotationCount 最大保留文件个数 RotationTime 设置文件分割时间 RotationCount 设置保留的最大文件数量
Types ¶
type Config ¶
type Config struct { AppName string `json:"app_name"` // 应用名 AppMode string `json:"app_mode"` // 应用环境 LogType string `json:"log_type"` // 日志类型 LogPath string `json:"log_path"` // 日志主路径 ChildPath string `json:"child_path"` // 日志子路径+文件名 RotationSize int64 `json:"rotation_size"` // 单个文件大小 RotationCount uint `json:"rotation_count"` // 可以保留的文件个数 NoBuffWrite bool `json:"no_buff_write"` // 设置无缓冲日志写入 RotationTime time.Duration `json:"rotation_time"` // 日志分割的时间 MaxAge time.Duration `json:"max_age"` // 日志最大保留的天数 }
type LogContext ¶
type LogContext struct {
// contains filtered or unexported fields
}
LogContext logger
func (*LogContext) ErrorF ¶
func (ctx *LogContext) ErrorF(template string, args ...interface{})
func (*LogContext) Field ¶
func (ctx *LogContext) Field(key string, value interface{}) Field
func (*LogContext) InfoF ¶
func (ctx *LogContext) InfoF(template string, args ...interface{})
func (*LogContext) WarnF ¶
func (ctx *LogContext) WarnF(template string, args ...interface{})
type LogOptionFunc ¶
type LogOptionFunc func(*Config)
func SetLogChildPath ¶
func SetLogChildPath(childPath string) LogOptionFunc
设置子目录—+文件名,保证一个类型的文件在同一个文件夹下面便于区分、默认值glogs/%Y-%m-%d.log
func SetLogMaxAge ¶
func SetLogMaxAge(maxAge time.Duration) LogOptionFunc
SetLogMaxAge 设置文件最大保留时间、默认值7天
func SetLogPath ¶
func SetLogPath(logPath string) LogOptionFunc
设置日志目录,这个是主目录,程序会给此目录拼接上项目名,子目录以及文件,默认值/home/logs/app
func SetLogType ¶
func SetLogType(logType string) LogOptionFunc
设置日志类型,日志类型目前分为2种,console和file,默认值file
func SetRotationCount ¶
func SetRotationCount(n uint) LogOptionFunc
SetRotationCount 设置保留的最大文件数量、没有默认值(表示不限制)
func SetRotationTime ¶
func SetRotationTime(rotationTime time.Duration) LogOptionFunc
SetRotationTime 设置文件分割时间、默认值24*time.Hour(按天分割)
Click to show internal directories.
Click to hide internal directories.