Skip to content

chore: modify log level#2793

Open
LinQingYuu wants to merge 1 commit intodevfrom
chore/log-level
Open

chore: modify log level#2793
LinQingYuu wants to merge 1 commit intodevfrom
chore/log-level

Conversation

@LinQingYuu
Copy link
Copy Markdown
Member

@LinQingYuu LinQingYuu commented May 3, 2026

将 HTTP 请求的日志等级下调为 Debug,以避免在网络环境不佳的情况下需要连续关掉一堆弹窗才能用启动器

(先生,这实在是太糟糕了,我的启动器全是无关紧要的错误弹窗)

Summary by Sourcery

降低 HTTP 请求重试失败日志的严重级别,在保留诊断信息的同时减少用户可见的错误噪声。

改进内容:

  • 将 HTTP 重试和请求尝试失败的日志从 error 级别降为 debug 级别,并用适当的模块对其进行标记。
  • 新增一个 debug 级别的日志重载方法,接受异常、消息和模块参数,以便对 HTTP 错误进行一致的结构化日志记录。
Original summary in English

Summary by Sourcery

Lower the log severity of HTTP request retry failures to reduce user-facing error noise while preserving diagnostic information.

Enhancements:

  • Change HTTP retry and request attempt failure logs from error level to debug level and tag them with appropriate modules.
  • Add a debug-level logging overload that accepts an exception, message, and module for consistent structured logging of HTTP errors.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XS PR 大小评估:微型 labels May 3, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 3, 2026

评审者指南(在小型 PR 上折叠)

评审者指南

将暂时性 HTTP 重试失败的日志级别从 Error 降低到 Debug,并扩展日志封装器以支持带异常和模块名的 Debug 日志,从而在网络问题期间减少面向用户的错误噪音。

HTTP 重试与调试级别日志的时序图

sequenceDiagram
    actor UserLauncher
    participant NetworkService
    participant RetryPolicy
    participant HttpSenderExtension
    participant LogWrapper

    UserLauncher->>NetworkService: GetRetryPolicy(retry, retryPolicy)
    NetworkService->>RetryPolicy: ExecuteAsync(operation)

    loop For_each_retry_attempt
        RetryPolicy->>HttpSenderExtension: SendAsync(request, cancellationToken)
        HttpSenderExtension-->>RetryPolicy: exception
        RetryPolicy->>LogWrapper: Debug(ex, message, module Request)
        RetryPolicy-->>NetworkService: onRetry(exception, timeSpan, retryAttempt)
        NetworkService->>LogWrapper: Debug(ex, message, module Network)
    end

    RetryPolicy-->>UserLauncher: final_result_or_failure
Loading

HTTP 重试流程中更新后日志行为的类图

classDiagram
    class NetworkService {
        +GetRetryPolicy(retry, retryPolicy) AsyncPolicy
    }

    class HttpSenderExtension {
        +SendAsync(request, cancellationToken) Task~HttpResponseMessage~
    }

    class LogWrapper {
        <<static>>
        +OnLog LogHandler
        +Debug(module, msg) void
        +Debug(msg) void
        +Debug(ex, message, module) void
        +Error(ex, message) void
        +Error(ex, message, module) void
    }

    NetworkService --> LogWrapper : uses_Debug_with_exception
    HttpSenderExtension --> LogWrapper : uses_Debug_with_exception
Loading

文件级变更

变更 详情 文件
将 HTTP 重试失败日志从 Error 降级为 Debug,并添加模块标签,以减少对用户暴露的噪声错误。
  • 将重试策略中的 HTTP 失败日志从 Error 改为 Debug 级别
  • 为 HTTP 重试失败日志添加明确的 "Network" 模块标签
  • 将 HTTP 发送尝试失败日志从 Error 改为 Debug 级别,并添加 "Request" 模块标签
PCL.Core/IO/Net/NetworkService.cs
PCL.Core/IO/Net/Http/HttpSenderExtension.cs
扩展 LogWrapper,以支持带异常和模块名的 Debug 级别日志。
  • 新增接受 Exception、message 和 module 的 Debug 重载,并将其通过 LogLevel.Debug 连接到底层的 OnLog 委托
PCL.Core/Logging/LogWrapper.cs

提示与命令

与 Sourcery 交互

  • 触发新评审: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub Issue: 通过回复某条评审评论,让 Sourcery 从该评论创建一个 issue。你也可以在评审评论下回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题中的任意位置写 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中的任意位置写 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成评审者指南: 在拉取请求中评论 @sourcery-ai guide,即可在任意时间(重新)生成评审者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可标记解决所有 Sourcery 评论。如果你已经处理了所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 评审: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 评审。如果你想从一次全新的评审开始,这尤其有用——别忘了再评论 @sourcery-ai review 以触发新的评审!

自定义你的体验

访问你的控制面板以:

  • 启用或禁用诸如 Sourcery 生成的拉取请求摘要、评审者指南等评审功能。
  • 更改评审语言。
  • 添加、移除或编辑自定义评审指令。
  • 调整其他评审设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Lowers log severity for transient HTTP retry failures from Error to Debug and extends the logging wrapper to support exception-bearing Debug logs with module names, reducing user-facing error noise during network issues.

Sequence diagram for HTTP retry and debug-level logging

sequenceDiagram
    actor UserLauncher
    participant NetworkService
    participant RetryPolicy
    participant HttpSenderExtension
    participant LogWrapper

    UserLauncher->>NetworkService: GetRetryPolicy(retry, retryPolicy)
    NetworkService->>RetryPolicy: ExecuteAsync(operation)

    loop For_each_retry_attempt
        RetryPolicy->>HttpSenderExtension: SendAsync(request, cancellationToken)
        HttpSenderExtension-->>RetryPolicy: exception
        RetryPolicy->>LogWrapper: Debug(ex, message, module Request)
        RetryPolicy-->>NetworkService: onRetry(exception, timeSpan, retryAttempt)
        NetworkService->>LogWrapper: Debug(ex, message, module Network)
    end

    RetryPolicy-->>UserLauncher: final_result_or_failure
Loading

Class diagram for updated logging behavior in HTTP retry flow

classDiagram
    class NetworkService {
        +GetRetryPolicy(retry, retryPolicy) AsyncPolicy
    }

    class HttpSenderExtension {
        +SendAsync(request, cancellationToken) Task~HttpResponseMessage~
    }

    class LogWrapper {
        <<static>>
        +OnLog LogHandler
        +Debug(module, msg) void
        +Debug(msg) void
        +Debug(ex, message, module) void
        +Error(ex, message) void
        +Error(ex, message, module) void
    }

    NetworkService --> LogWrapper : uses_Debug_with_exception
    HttpSenderExtension --> LogWrapper : uses_Debug_with_exception
Loading

File-Level Changes

Change Details Files
Downgrade HTTP retry failure logs from Error to Debug and tag them with modules to reduce noisy user-facing errors.
  • Change retry policy HTTP failure logging from Error to Debug level
  • Add explicit "Network" module tag to HTTP retry failure logs
  • Change HTTP send attempt failure logging from Error to Debug level and add a "Request" module tag
PCL.Core/IO/Net/NetworkService.cs
PCL.Core/IO/Net/Http/HttpSenderExtension.cs
Extend LogWrapper to support Debug-level logs with exceptions and module names.
  • Introduce Debug overload that accepts Exception, message, and module, wiring it to the underlying OnLog delegate with LogLevel.Debug
PCL.Core/Logging/LogWrapper.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些总体反馈:

  • 新增的 Debug(Exception ex, string message, string module) 重载与现有的 Debug(string? module, string msg) 重载在参数顺序模式上不一致(一个是 module 在最后,一个是 module 在最前),可能会引起混淆;建议统一参数顺序,或者再添加一个保持 module 为第一个参数的重载。
  • NetworkService.GetRetryPolicy 中,你现在将模块名硬编码为 "Network";如果网络栈的其他部分使用了不同的模块命名约定,建议将其提取为一个共享常量,或者确保所有日志调用在命名上保持一致。
供 AI Agent 使用的提示
Please address the comments from this code review:

## Overall Comments
- The newly added `Debug(Exception ex, string message, string module)` overload has a different parameter ordering pattern than the existing `Debug(string? module, string msg)` overloads (module first vs last), which may cause confusion; consider aligning the order or adding an overload that keeps `module` as the first argument.
- In `NetworkService.GetRetryPolicy`, you now hardcode the module name as `"Network"`; if other parts of the networking stack use a different module naming convention, consider extracting this into a shared constant or ensuring consistency across all logging calls.

Sourcery 对开源项目免费——如果你喜欢我们的代码审查,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈持续改进代码审查。
Original comment in English

Hey - I've left some high level feedback:

  • The newly added Debug(Exception ex, string message, string module) overload has a different parameter ordering pattern than the existing Debug(string? module, string msg) overloads (module first vs last), which may cause confusion; consider aligning the order or adding an overload that keeps module as the first argument.
  • In NetworkService.GetRetryPolicy, you now hardcode the module name as "Network"; if other parts of the networking stack use a different module naming convention, consider extracting this into a shared constant or ensuring consistency across all logging calls.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The newly added `Debug(Exception ex, string message, string module)` overload has a different parameter ordering pattern than the existing `Debug(string? module, string msg)` overloads (module first vs last), which may cause confusion; consider aligning the order or adding an overload that keeps `module` as the first argument.
- In `NetworkService.GetRetryPolicy`, you now hardcode the module name as `"Network"`; if other parts of the networking stack use a different module naming convention, consider extracting this into a shared constant or ensuring consistency across all logging calls.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@LinQingYuu LinQingYuu requested a review from a team May 3, 2026 21:17
public static void Debug(string? module, string msg) => OnLog?.Invoke(LogLevel.Debug, msg, module);
public static void Debug(string msg) => Debug(null, msg);

public static void Debug(Exception ex, string message, string module) => OnLog?.Invoke(LogLevel.Debug, message, module, ex);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

可以考虑把 messagemodule 调换下位置🤔

Copy link
Copy Markdown
Contributor

@ruattd ruattd left a comment

Choose a reason for hiding this comment

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

直接提取出信息写入 message 即可
Debug 等级不支持回报 ex 的原因就是它没必要回报

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XS PR 大小评估:微型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants