fix(logger): improve log writer initialization and error handling#50
Merged
OrenZhang merged 6 commits intolinux-do:masterfrom Jul 7, 2025
Merged
fix(logger): improve log writer initialization and error handling#50OrenZhang merged 6 commits intolinux-do:masterfrom
OrenZhang merged 6 commits intolinux-do:masterfrom
Conversation
OrenZhang
suggested changes
Jul 4, 2025
OrenZhang
suggested changes
Jul 4, 2025
OrenZhang
reviewed
Jul 4, 2025
3452469 to
4e7948f
Compare
There was a problem hiding this comment.
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不够直观,建议重命名为initErr或writerErr,以更清晰地表达其作为初始化错误的含义。
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
reviewed
Jul 6, 2025
…mprove readability
OrenZhang
approved these changes
Jul 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
例行检查
关联信息
无
变更内容
1,修复日志目录的创建
2,简化错误处理
3,
json tag错误变更原因
1,修复日志轮转的错误
2,
json tag错误导致数据库索引未创建