1
0

refactor: 后端日志系统重构

- 新增模块化日志器(pkg/logger/module.go)
- 新增 GORM 日志适配器
- 统一日志入口,移除所有 zap.L() 全局 logger 调用
- 字段标准化
- 启动阶段使用结构化日志
- 更新所有相关测试
This commit is contained in:
2026-04-23 18:37:51 +08:00
parent 8c075194e5
commit 280099b89c
33 changed files with 1105 additions and 161 deletions

View File

@@ -50,6 +50,7 @@ func New(cfg Config) (*zap.Logger, error) {
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
EncodeName: encodeLoggerName,
})
stdoutCore := zapcore.NewCore(
@@ -115,3 +116,10 @@ func logFileName() string {
func logFilePath(dir string) string {
return filepath.Join(dir, logFileName())
}
// encodeLoggerName 自定义 logger 名称编码器,输出 [name] 格式
func encodeLoggerName(name string, enc zapcore.PrimitiveArrayEncoder) {
if name != "" {
enc.AppendString("[" + name + "]")
}
}