Skip to content

fix: 移除 enable_logging 错误拦截#1920

Closed
LaoYueHanNi wants to merge 1 commit intofarion1231:mainfrom
LaoYueHanNi:fix/usage-logging
Closed

fix: 移除 enable_logging 错误拦截#1920
LaoYueHanNi wants to merge 1 commit intofarion1231:mainfrom
LaoYueHanNi:fix/usage-logging

Conversation

@LaoYueHanNi
Copy link
Copy Markdown

@LaoYueHanNi LaoYueHanNi commented Apr 6, 2026

问题描述

使用统计(Usage Statistics)在升级到某个版本后不再记录到数据库 proxy_request_logs 表中。

问题原因

提交: bf40b01

这个提交本意是:当用户关闭"启用日志记录"开关时,跳过 HTTP请求详情的日志写入。但同时跳过了使用统计记录,导致未开启日志记录时,使用统计无法记录。

问题代码

src-tauri/src/proxy/response_processor.rs 中有两处问题代码:

1. 流式响应处理(第 283-302 行):
SseUsageCollector::new(start_time, move |events, first_token_ms| {
    if !logging_enabled {
        return;  // 错误:同时跳过了使用统计记录
    }
    // ...
});

2. 非流式响应处理(第 366-371 行):
fn spawn_log_usage(...) {
    if let Ok(config) = state.config.try_read() {
        if !config.enable_logging {
            return;  // 错误:同时跳过了使用统计记录
        }
    }
    // ...
}

修复内容

  1. 移除 enable_logging 检查:删除 response_processor.rs 中两处对 enable_logging
    的检查,让使用统计始终记录,不受日志开关影响

测试计划

  • 关闭"启用日志记录"开关,验证使用统计仍能正常记录
  • 开启"启用日志记录"开关,验证使用统计能正常记录
  • 验证数据库 proxy_request_logs 表中有数据
  • 已通过 cargo test proxy --lib 测试 (296 passed)

@LaoYueHanNi
Copy link
Copy Markdown
Author

LaoYueHanNi commented Apr 6, 2026

失误关闭的PR 操作失误把上个pr关闭了,现在已rebase好重新提交。

@yovinchen
Copy link
Copy Markdown
Collaborator

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0393e08d3c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/commands/proxy.rs Outdated
Comment thread src-tauri/src/commands/proxy.rs Outdated
问题描述:
- 使用统计(Usage Statistics)在关闭"启用日志记录"开关后不再记录到数据库
- 这是因为 bf40b01 提交错误地同时跳过了使用统计记录

修复内容:
- 移除 response_processor.rs 中两处对 enable_logging 的检查,让使用统计始终记录
@LaoYueHanNi LaoYueHanNi changed the title fix: 移除 enable_logging 错误拦截并使配置实时生效 fix: 移除 enable_logging 错误拦截 Apr 7, 2026
@farion1231
Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Owner

@farion1231 farion1231 left a comment

Choose a reason for hiding this comment

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

[P1] 这个 PR 修复了“统计不再入库”,但同时也把“关闭日志后不再持久化代理请求”这层语义一起撤销了。PR 删除了 response_processor.rs (line 404) 和 response_processor.rs (line 472) 两处 enable_logging 早退;而实际写入仍然走 logger.rs (line 76) 的 INSERT OR REPLACE INTO proxy_request_logs。问题在于“请求日志”页后台查询同样直接读取这张表,而且没有按配置或数据源过滤,见 usage_stats.rs (line 615) 和 usage_stats.rs (line 681)。也就是说,用户一旦关闭“启用日志记录”,这个 PR 仍会继续把代理请求写回来,并在 Request Logs 页重新展示

@LaoYueHanNi LaoYueHanNi closed this May 4, 2026
@LaoYueHanNi LaoYueHanNi reopened this May 6, 2026
@LaoYueHanNi
Copy link
Copy Markdown
Author

[P1] 这个 PR 修复了“统计不再入库”,但同时也把“关闭日志后不再持久化代理请求”这层语义一起撤销了。PR 删除了 response_processor.rs (line 404) 和 response_processor.rs (line 472) 两处 enable_logging 早退;而实际写入仍然走 logger.rs (line 76) 的 INSERT OR REPLACE INTO proxy_request_logs。问题在于“请求日志”页后台查询同样直接读取这张表,而且没有按配置或数据源过滤,见 usage_stats.rs (line 615) 和 usage_stats.rs (line 681)。也就是说,用户一旦关闭“启用日志记录”,这个 PR 仍会继续把代理请求写回来,并在 Request Logs 页重新展示

您好,当前更新到3.14.1后发现,关闭启用日志记录,同样还是会写入到request log,只不过换了个名头叫session。想知道这和回复的想法是否相悖,用户关闭开关,还是有记录到数据库表中,是否说明记录使用统计就是应该是常驻的刚需功能,而不应该有这个开关,不是的话是否应该移除这个session自动写入,或者说让这个session写入log也受开关的控制。
此pr我已关闭,做废弃处理
image

@LaoYueHanNi LaoYueHanNi closed this May 6, 2026
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