Documentation
¶
Index ¶
- Constants
- func GetRequestBody(ctx *gin.Context, strip bool) string
- func GetRequestID(ctx *gin.Context) string
- func GinCors(ctx *gin.Context)
- func GinLogHttpFail(ctx *gin.Context, err error)
- func GinLogger(appendHandle func(ctx *gin.Context) []zap.Field) func(ctx *gin.Context)
- func GinPrintInitRoute(httpMethod, absolutePath, handlerName string, nuHandlers int)
- func GinRecovery(ctx *gin.Context)
- func IsModifyMethod(method string) bool
- func NewGorm2Logger() logger.Interface
- type DBLogger
- type EsLogger
- type InterFace
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) DebugRecord(module string, msg string, filed ...zap.Field)
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(msg string)
- func (l *Logger) ErrorRecord(module string, msg string, filed ...zap.Field)
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Info(msg string)
- func (l *Logger) InfoRecord(module string, msg string, filed ...zap.Field)
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Warn(msg string)
- func (l *Logger) WarnRecord(module string, msg string, filed ...zap.Field)
- func (l *Logger) Warnf(format string, args ...interface{})
- type RedisHook
- func (r RedisHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error
- func (r RedisHook) AfterProcessPipeline(ctx context.Context, cmdItems []redis.Cmder) error
- func (r RedisHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)
- func (r RedisHook) BeforeProcessPipeline(ctx context.Context, cmdItems []redis.Cmder) (context.Context, error)
Constants ¶
View Source
const ( XRequestID = "x-request-id" // 请求ID名称 XRequestIDPrefix = "R" // 当使用纳秒时间戳作为请求ID时拼接的前缀字符串 TextGinRouteInit = "gin.route.init" // gin 路由注册日志标记 TextGinPanic = "gin.panic.recovery" // gin panic日志标记 TextGinRequest = "gin.request" // gin request请求日志标记 TextGinResponseFail = "gin.response.fail" // gin 业务层面失败响应日志标记 TextGinPreflight = "gin.preflight" // gin preflight 预检options请求类型日志 )
XRequestID 为每个请求分配的请求编号key和名称 1、优先从header头里读由nginx维护的并且转发过来的x-request-id 2、如果读取不到则使用当前纳秒时间戳字符串加前缀字符串
Variables ¶
This section is empty.
Functions ¶
func GetRequestBody ¶
GetRequestBody 获取请求body体
- strip 是否要将JSON类型的body体去除反斜杠和大括号,以便于Es等不做深层字段解析而当做一个字符串
func GinLogger ¶
GinLogger zap实现的gin-logger日志中间件<gin.HandlerFunc的实现>
- appendHandle 额外补充的自定义添加字段方法,可选参数
func GinPrintInitRoute ¶
GinPrintInitRoute 为gin自定义注册路由日志输出
注意:因gin路由注册信息输出只有dev模式才有 若为了全面记录路由注册日志,调用 gin.SetMode 方法代码可写在路由注册之后,但就会出现gin的开发模式提示信息
func GinRecovery ¶
GinRecovery zap实现的gin-recovery日志中间件<gin.HandlerFunc的实现>
Types ¶
type Logger ¶
Logger logger封装, 实现第三方库的日志接口
func New ¶
New 初始化单例logger
-- level 日志级别:debug、info、warning 等 -- path 文件形式的日志路径 or 标准输出 stderr -- recordField 指定xxxRecord系列方法额外添加分门别类的方法的字段名称
func (*Logger) DebugRecord ¶
DebugRecord 分module记录日志debug级别日志
-- module 自定义module名称,即添加至日志JSON中的module的值,便于Es按module字段值分类别类检索 -- msg 日志msg -- ...filed 可选的自定义添加的字段
func (*Logger) ErrorRecord ¶
ErrorRecord 分module记录日志error级别日志
-- module 自定义module名称,即添加至日志JSON中的module的值,便于Es按module字段值分类别类检索 -- msg 日志msg -- ...filed 可选的自定义添加的字段
func (*Logger) InfoRecord ¶
InfoRecord 分module记录日志info级别日志
-- module 自定义module名称,即添加至日志JSON中的module的值,便于Es按module字段值分类别类检索 -- msg 日志msg -- ...filed 可选的自定义添加的字段
func (*Logger) WarnRecord ¶
WarnRecord 分module记录日志warn级别日志
-- module 自定义module名称,即添加至日志JSON中的module的值,便于Es按module字段值分类别类检索 -- msg 日志msg -- ...filed 可选的自定义添加的字段
type RedisHook ¶
type RedisHook struct{}
RedisHook redis hook implement
func (RedisHook) AfterProcess ¶
AfterProcess redis执行命令后hook
func (RedisHook) AfterProcessPipeline ¶
AfterProcessPipeline redis执行pipe后hook
func (RedisHook) BeforeProcess ¶
BeforeProcess redis执行命令前hook
Click to show internal directories.
Click to hide internal directories.