Documentation
¶
Overview ¶
* @Author: justin-ren * @Date: 2025-03-01 02:50:20 * @LastEditors: justin-ren * @LastEditTime: 2025-03-04 13:25:36 * @FilePath: /xlogrus/gin_log.go * @Description: gin event log *
* @Author: justin-ren * @Date: 2025-03-01 02:52:00 * @LastEditors: justin-ren * @LastEditTime: 2025-03-04 13:31:12 * @FilePath: /xlogrus/gorm_log.go * @Description: gorm event log *
* @Author: justin-ren * @Date: 2025-02-26 02:11:15 * @LastEditors: justin-ren * @LastEditTime: 2025-03-03 23:22:06 * @FilePath: /xlogrus-edit/xlogrus/xlogrus.go * @Description: *
Index ¶
- func NewGinLog(setFunc ...c.LogOption[GinOpt]) (*TLogrus, gin.HandlerFunc, *GinOpt, error)
- func NewGormLog(setFunc ...c.LogOption[GormOpt]) (*GormLog, *GormOpt, error)
- func NewUserLog(setFunc ...c.LogOption[UserOpt]) (*TLogrus, *UserOpt, error)
- func WithBKeywords[T any, PT interface{ ... }](keywords []BannedKeyword) c.LogOption[T]
- func WithErrLogPrefix[T any, PT interface{ ... }](prefix string) c.LogOption[T]
- func WithErrLogSuffix[T any, PT interface{ ... }](suffix string) c.LogOption[T]
- func WithFileNamePrefix[T any, PT interface{ ... }](prefix string) c.LogOption[T]
- func WithFileNameSuffixTimeFormat[T any, PT interface{ ... }](format string) c.LogOption[T]
- func WithGormLogLevel[T any, PT interface{ ... }](level string) c.LogOption[T]
- func WithIsHelper[T any, PT interface{ ... }](value bool) c.LogOption[T]
- func WithKeepCount[T any, PT interface{ ... }](count int) c.LogOption[T]
- func WithLogFileTimeFormat[T any, PT interface{ ... }](format string) c.LogOption[T]
- func WithLogLatency[T any, PT interface{ ... }](value bool) c.LogOption[T]
- func WithLogLevel[T any, PT interface{ ... }](logLevel string) c.LogOption[T]
- func WithLogPath[T any, PT interface{ ... }](path string) c.LogOption[T]
- func WithSetErrFileHook[T any, PT interface{ ... }](enabled bool) c.LogOption[T]
- func WithSkipErrRecordNotFound[T any, PT interface{ ... }](value bool) c.LogOption[T]
- func WithSkipRoute[T any, PT interface{ ... }](r map[string]struct{}) c.LogOption[T]
- func WithSlowThreshold[T any, PT interface{ ... }](threshold time.Duration) c.LogOption[T]
- func WithStdoutTimeFormat[T any, PT interface{ ... }](format string) c.LogOption[T]
- type BannedKeyword
- type GinOpt
- type GormLog
- func (gormLog *GormLog) Error(ctx context.Context, msg string, args ...interface{})
- func (gormLog *GormLog) Info(ctx context.Context, msg string, args ...interface{})
- func (gormLog *GormLog) LogMode(level logger.LogLevel) logger.Interface
- func (gormLog *GormLog) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (gormLog *GormLog) Warn(ctx context.Context, msg string, args ...interface{})
- type GormOpt
- func (g *GormOpt) SetBKeywords(keywords []BannedKeyword) error
- func (g *GormOpt) SetGormLoglevel(level string) error
- func (g *GormOpt) SetIsHelper(value bool) error
- func (g *GormOpt) SetLogLatency(value bool) error
- func (g *GormOpt) SetSkipErrRecordNotFound(value bool) error
- func (g *GormOpt) SetSlowThreshold(threshold time.Duration) error
- type TGormLog
- type TLogrus
- type UserOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithBKeywords ¶
func WithBKeywords[ T any, PT interface { *T SetBKeywords([]BannedKeyword) error }, ](keywords []BannedKeyword) c.LogOption[T]
WithBKeywords 设置禁用关键词列表
func WithErrLogPrefix ¶
func WithErrLogPrefix[ T any, PT interface { *T SetErrLogPrefix(string) error }, ](prefix string) c.LogOption[T]
WithErrLogPrefix 设置错误日志前缀
func WithErrLogSuffix ¶
func WithErrLogSuffix[ T any, PT interface { *T SetErrLogSuffix(string) error }, ](suffix string) c.LogOption[T]
WithErrLogSuffix 设置错误日志后缀
func WithFileNamePrefix ¶
func WithFileNamePrefix[ T any, PT interface { *T // 1. 必须是指向 T 的指针类型(比如 *UserOpt) SetFileNamePrefix(string) error // 2. 必须实现指定签名的方法 }, ](prefix string) c.LogOption[T]
WithFileNamePrefix sets the filename prefix. 定义泛型函数 WithFileNamePrefix,用于创建设置文件名前缀的选项
func WithFileNameSuffixTimeFormat ¶
func WithFileNameSuffixTimeFormat[ T any, PT interface { *T SetFileNameSuffixTimeFormat(string) error }, ](format string) c.LogOption[T]
WithFileNameSuffixTimeFormat 设置文件名后缀时间格式
func WithGormLogLevel ¶
func WithGormLogLevel[ T any, PT interface { *T SetGormLoglevel(string) error }, ](level string) c.LogOption[T]
WithGormLogLevel 设置 GORM 日志级别
func WithIsHelper ¶
WithIsHelper 设置是否为帮助函数
func WithKeepCount ¶
WithKeepCount 设置日志保留数量
func WithLogFileTimeFormat ¶
func WithLogFileTimeFormat[ T any, PT interface { *T SetLogFileTimeFormat(string) error }, ](format string) c.LogOption[T]
WithLogFileTimeFormat 设置日志文件时间格式
func WithLogLatency ¶
func WithLogLatency[ T any, PT interface { *T SetLogLatency(bool) error }, ](value bool) c.LogOption[T]
WithLogLatency 设置是否记录延迟
func WithLogLevel ¶
func WithLogLevel[ T any, PT interface { *T SetLogLevel(string) error }, ](logLevel string) c.LogOption[T]
WithLogLevel 设置日志级别
func WithLogPath ¶
func WithLogPath[ T any, PT interface { *T SetLogPath(string) error }, ](path string) c.LogOption[T]
WithLogPath 设置日志路径
func WithSetErrFileHook ¶
func WithSetErrFileHook[ T any, PT interface { *T SetSetErrFileHook(bool) error }, ](enabled bool) c.LogOption[T]
WithSetErrFileHook 设置是否分离错误日志
func WithSkipErrRecordNotFound ¶
func WithSkipErrRecordNotFound[ T any, PT interface { *T SetSkipErrRecordNotFound(bool) error }, ](value bool) c.LogOption[T]
为 GormOpt 的字段生成 With 函数 WithSkipErrRecordNotFound 设置是否忽略记录未找到错误
func WithSkipRoute ¶
Types ¶
type BannedKeyword ¶
type GinOpt ¶
func (*GinOpt) SetSkipRoute ¶
type GormLog ¶
type GormOpt ¶
type GormOpt struct {
//ignore if NotFound error happened
SkipErrRecordNotFound bool
//slow sql threshold
SlowThreshold time.Duration
//record line number and filename
IsHelper bool
//replace sensitive word, such as password
BKeywords []BannedKeyword
// if set to true, it will add latency information for your queries
LogLatency bool
//gorm log level for automatically triggering
//logrus log level is debug and don't need to modify
GormLogLevel logger.LogLevel
*c.OptLog
}
func (*GormOpt) SetBKeywords ¶
func (g *GormOpt) SetBKeywords(keywords []BannedKeyword) error
SetBKeywords 设置 BKeywords 字段
func (*GormOpt) SetGormLoglevel ¶
SetGormLoglevel 方法 level支持 silent, error, warn, warning,info
func (*GormOpt) SetIsHelper ¶
SetIsHelper 设置 IsHelper 字段
func (*GormOpt) SetLogLatency ¶
SetLogLatency 设置 LogLatency 字段
func (*GormOpt) SetSkipErrRecordNotFound ¶
SetSkipErrRecordNotFound 设置 SkipErrRecordNotFound 字段