logger

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package logger 提供统一的日志记录功能 本文件实现了基于logrus的日志系统,支持日志轮转、多级别配置和结构化日志记录

Index

Constants

This section is empty.

Variables

View Source
var Logger *logrus.Logger

Logger 是日志记录器实例,全局单例

Functions

func Add

func Add(requestId, info string, err error)

Add 函数用于添加带请求ID的结构化日志记录 该函数会: 1. 根据是否有错误选择日志级别 2. 记录包含请求ID、信息和错误的结构化日志 参数:

  • requestId: 请求标识符
  • info: 日志信息
  • err: 错误信息(可为nil)

func Debug

func Debug(msg string, arg ...any)

Debug 记录Debug级别的日志,支持格式化字符串(自动脱敏)

func DebugWithFields

func DebugWithFields(fields map[string]any, msg string, arg ...any)

DebugWithFields 带结构化字段的Debug日志(字段和消息自动脱敏)

func Error

func Error(msg string, arg ...any)

Error 记录Error级别的日志,支持格式化字符串(自动脱敏)

func ErrorWithFields

func ErrorWithFields(fields map[string]any, msg string, arg ...any)

ErrorWithFields 带结构化字段的Error日志(字段和消息自动脱敏)

func GetLevel added in v1.0.5

func GetLevel() string

GetLevel 获取当前日志级别

func Info

func Info(msg string, arg ...any)

Info 记录Info级别的日志,支持格式化字符串(自动脱敏)

func InfoWithFields

func InfoWithFields(fields map[string]any, msg string, arg ...any)

InfoWithFields 带结构化字段的Info日志(字段和消息自动脱敏)

func InitLogger

func InitLogger(loggersConfig config.LoggersConfig) *logrus.Logger

InitLogger 根据配置初始化日志记录器 该函数会: 1. 创建新的logrus日志记录器 2. 设置日志级别为Trace(最高级别) 3. 为每个日志级别配置对应的输出 4. 支持自定义日志配置和默认配置回退 参数:

  • loggersConfig: 日志配置信息

返回:

  • *logrus.Logger: 配置完成的日志记录器

func MaskValue

func MaskValue(value string) string

MaskValue 对敏感值进行脱敏处理 保留首尾各2个字符,中间用****替换

func SanitizeFields

func SanitizeFields(fields map[string]any) logrus.Fields

SanitizeFields 对字段进行脱敏处理 自动检测敏感字段并进行脱敏

func SanitizeMessage

func SanitizeMessage(msg string) string

SanitizeMessage 对消息内容进行脱敏处理 自动检测并脱敏消息中的敏感信息

func SetLevel added in v1.0.5

func SetLevel(level string) error

SetLevel 动态设置日志级别 支持的级别:trace, debug, info, warn/warning, error, fatal, panic 大小写不敏感

func Trace

func Trace(msg string, arg ...any)

Trace 记录Trace级别的日志(自动脱敏)

func TraceWithFields

func TraceWithFields(fields map[string]any, msg string, arg ...any)

TraceWithFields 带结构化字段的Trace日志(字段和消息自动脱敏)

func Warn

func Warn(msg string, arg ...any)

Warn 记录Warn级别的日志,支持格式化字符串(自动脱敏)

func WarnWithFields

func WarnWithFields(fields map[string]any, msg string, arg ...any)

WarnWithFields 带结构化字段的Warn日志(字段和消息自动脱敏)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL