Skip to content

[GFX-189] feature/GFX-189 - #96

Open
AlianBlank wants to merge 2 commits into
mainfrom
feature/GFX-189
Open

[GFX-189] feature/GFX-189#96
AlianBlank wants to merge 2 commits into
mainfrom
feature/GFX-189

Conversation

@AlianBlank

@AlianBlank AlianBlank commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Linear: GFX-189

Summary by CodeRabbit

  • 重构

    • 优化日志系统的配置流程,提升配置可维护性,同时保留现有日志输出能力。
  • 测试

    • 新增日志创建、参数校验、配置回调和日志目录自动创建等场景的测试。
    • 改进资源管理器释放测试,明确验证释放操作不会抛出异常。

将 LogHandler.Create 的 Cognitive Complexity 由 34 降至 ≤5(Sonar S3776 修复)。

方法体只保留入口协调(参数校验 / Serilog 诊断调用 / 路径解析 / sink 装配调用 / 默认 logger 设置),其
余职责抽到 11 个 private static helper:ResolveLogPath / SelectOutputTemplates / ApplyLoki /
BuildLokiLabels / ApplyLokiProperties / WriteLokiSink / BuildLokiCredentials / ApplyMongoDb /
ApplyFile / ApplyConsole / ApplyMinimumLevel。public 签名与可观察行为零变更。

新增 GameFrameX.Foundation.Tests/Logger/LogHandlerCreateTests.cs 5 个 [Fact] 覆盖参数校验、
可用 logger 返回、configurationAction 回调、目录自动创建,使用独立 [Collection] 与 per-test 临时
目录隔离全局 Serilog / LogHelper 状态。dotnet build 0 错误,dotnet test 1802 通过 / 0 失败。

Linear: GFX-186
@linear-code

linear-code Bot commented Jul 29, 2026

Copy link
Copy Markdown

GFX-189

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

LogHandler.Create 将日志配置流程拆分为路径解析、模板选择及各类 sink 装配方法,并保留全局 logger 设置与异常处理行为。新增创建流程测试,同时调整资源释放测试的异常断言方式。

日志创建流程

Layer / File(s) Summary
创建流程与路径模板配置
GameFrameX.Foundation.Logger/LogHandler.cs
Create 负责协调基础 logger 配置、日志路径创建、标签模板选择及输出装配。
日志输出目标与最低级别装配
GameFrameX.Foundation.Logger/LogHandler.cs
Loki、MongoDB、文件、控制台 sink、凭证、属性、标签、压缩和最低级别配置分别由私有方法处理。
创建行为与资源释放测试
GameFrameX.Foundation.Tests/Logger/LogHandlerCreateTests.cs, GameFrameX.Foundation.Tests/Localization/ResourceManagerTests.cs
新增 LogHandler.Create 参数校验、返回值、配置回调和目录创建测试,并使用 Record.Exception 验证 Dispose 不抛异常。

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive 标题仅包含工单号和分支名,未说明实际变更内容,无法快速看出核心改动。 请改为描述主要改动,例如“重构 LogHandler.Create 并补充创建行为测试”。
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/GFX-189

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@GameFrameX.Foundation.Logger/LogHandler.cs`:
- Line 215: Update the fallback filename expression near logFileName to treat an
empty or whitespace-only LogTagName as absent, falling back to LogType instead
of producing _.log; preserve the existing explicit LogFileName precedence and
append _.log to the selected type or tag.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ca83f3cc-0335-4119-90f2-f20489991d39

📥 Commits

Reviewing files that changed from the base of the PR and between 344f6d8 and 76a33fb.

📒 Files selected for processing (3)
  • GameFrameX.Foundation.Logger/LogHandler.cs
  • GameFrameX.Foundation.Tests/Localization/ResourceManagerTests.cs
  • GameFrameX.Foundation.Tests/Logger/LogHandlerCreateTests.cs

private static string ResolveLogPath(LogOptions logOptions, bool isDefault)
{
// 文件名
var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace() ? logOptions.LogFileName : $"{logOptions.LogTagName ?? logOptions.LogType}_.log";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

LogTagName 时默认文件名错误。

LogTagName 默认是空字符串,?? 不会回退到 LogType,因此未指定 LogFileName 时会生成 _.log,而不是预期的 {LogType}_.log

建议修复
- var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace() ? logOptions.LogFileName : $"{logOptions.LogTagName ?? logOptions.LogType}_.log";
+ var fileNamePrefix = logOptions.LogTagName.IsNotNullOrEmptyOrWhiteSpace()
+     ? logOptions.LogTagName
+     : logOptions.LogType;
+ var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace()
+     ? logOptions.LogFileName
+     : $"{fileNamePrefix}_.log";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace() ? logOptions.LogFileName : $"{logOptions.LogTagName ?? logOptions.LogType}_.log";
var fileNamePrefix = logOptions.LogTagName.IsNotNullOrEmptyOrWhiteSpace()
? logOptions.LogTagName
: logOptions.LogType;
var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace()
? logOptions.LogFileName
: $"{fileNamePrefix}_.log";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@GameFrameX.Foundation.Logger/LogHandler.cs` at line 215, Update the fallback
filename expression near logFileName to treat an empty or whitespace-only
LogTagName as absent, falling back to LogType instead of producing _.log;
preserve the existing explicit LogFileName precedence and append _.log to the
selected type or tag.

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.

1 participant