Skip to content

fix(logger): improve log writer initialization and error handling#50

Merged
OrenZhang merged 6 commits intolinux-do:masterfrom
deloz:master
Jul 7, 2025
Merged

fix(logger): improve log writer initialization and error handling#50
OrenZhang merged 6 commits intolinux-do:masterfrom
deloz:master

Conversation

@deloz
Copy link
Copy Markdown
Contributor

@deloz deloz commented Jul 3, 2025

例行检查

  • 我已阅读并理解 贡献者公约
  • 我已阅读并同意 贡献者许可协议 (CLA),确认我的贡献将根据项目的 MIT 许可证进行许可,
  • 我知晓如果此 PR 并不做出实质性更改,或可被认为是为了PR被合并而提交PR的,则可能不会被合并,

关联信息

变更内容

1,修复日志目录的创建
2,简化错误处理
3, json tag错误

变更原因

1,修复日志轮转的错误
2, json tag错误导致数据库索引未创建

This comment was marked as outdated.

@deloz deloz force-pushed the master branch 2 times, most recently from 3452469 to 4e7948f Compare July 4, 2025 14:33
@OrenZhang OrenZhang requested a review from Copilot July 6, 2025 04:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

该 PR 主要改进了日志写入器的初始化逻辑并修复了 OAuth 用户模型中的标签错误

  • 将日志写入器初始化抽取为 initWriter 并改为返回 error,避免直接 fatal
  • 使用 sync.Once 保证写入器只初始化一次
  • 修复 User.LastLoginAt 的 JSON 标签和 GORM 索引标签分隔错误

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/logger/utils.go 提取并简化日志写入器初始化,返回错误而非直接 log.Fatalf,使用 sync.Once 确保幂等
internal/logger/logger.go init 中获取并检查日志写入器错误,替换原先匿名调用 GetLogWriter 的方式
internal/apps/oauth/models.go 修正 LastLoginAt 字段的标签,将索引标签分离到 gorm:"index"
Comments suppressed due to low confidence (3)

internal/logger/utils.go:45

  • [nitpick] 变量名 errOnce 不够直观,建议重命名为 initErrwriterErr,以更清晰地表达其作为初始化错误的含义。
	errOnce error

internal/logger/utils.go:43

  • [nitpick] 全局变量 writer 名称过于笼统,建议改为 logWriter 以提高可读性并明确其用途。
	writer  zapcore.WriteSyncer

internal/logger/utils.go:49

  • 缺少针对日志写入器初始化失败场景的单元测试,建议添加测试用例以覆盖 initWriter 返回错误的分支,确保异常处理逻辑有效。
func GetLogWriter() (zapcore.WriteSyncer, error) {

OrenZhang

This comment was marked as outdated.

@OrenZhang OrenZhang merged commit 0371c85 into linux-do:master Jul 7, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants