Documentation
¶
Overview ¶
Package logger 提供统一的日志记录功能 本文件实现了基于logrus的日志系统,支持日志轮转、多级别配置和结构化日志记录
Index ¶
- Variables
- func Add(requestId, info string, err error)
- func Debug(msg string, arg ...any)
- func DebugWithFields(fields map[string]any, msg string, arg ...any)
- func Error(msg string, arg ...any)
- func ErrorWithFields(fields map[string]any, msg string, arg ...any)
- func GetLevel() string
- func Info(msg string, arg ...any)
- func InfoWithFields(fields map[string]any, msg string, arg ...any)
- func InitLogger(loggersConfig config.LoggersConfig) *logrus.Logger
- func MaskValue(value string) string
- func SanitizeFields(fields map[string]any) logrus.Fields
- func SanitizeMessage(msg string) string
- func SetLevel(level string) error
- func Trace(msg string, arg ...any)
- func TraceWithFields(fields map[string]any, msg string, arg ...any)
- func Warn(msg string, arg ...any)
- func WarnWithFields(fields map[string]any, msg string, arg ...any)
Constants ¶
This section is empty.
Variables ¶
View Source
var Logger *logrus.Logger
Logger 是日志记录器实例,全局单例
Functions ¶
func Add ¶
Add 函数用于添加带请求ID的结构化日志记录 该函数会: 1. 根据是否有错误选择日志级别 2. 记录包含请求ID、信息和错误的结构化日志 参数:
- requestId: 请求标识符
- info: 日志信息
- err: 错误信息(可为nil)
func DebugWithFields ¶
DebugWithFields 带结构化字段的Debug日志(字段和消息自动脱敏)
func ErrorWithFields ¶
ErrorWithFields 带结构化字段的Error日志(字段和消息自动脱敏)
func InfoWithFields ¶
InfoWithFields 带结构化字段的Info日志(字段和消息自动脱敏)
func InitLogger ¶
func InitLogger(loggersConfig config.LoggersConfig) *logrus.Logger
InitLogger 根据配置初始化日志记录器 该函数会: 1. 创建新的logrus日志记录器 2. 设置日志级别为Trace(最高级别) 3. 为每个日志级别配置对应的输出 4. 支持自定义日志配置和默认配置回退 参数:
- loggersConfig: 日志配置信息
返回:
- *logrus.Logger: 配置完成的日志记录器
func SanitizeFields ¶
SanitizeFields 对字段进行脱敏处理 自动检测敏感字段并进行脱敏
func SanitizeMessage ¶
SanitizeMessage 对消息内容进行脱敏处理 自动检测并脱敏消息中的敏感信息
func SetLevel ¶ added in v1.0.5
SetLevel 动态设置日志级别 支持的级别:trace, debug, info, warn/warning, error, fatal, panic 大小写不敏感
func TraceWithFields ¶
TraceWithFields 带结构化字段的Trace日志(字段和消息自动脱敏)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.