fix(serve): standard Apache Combined Log Format for HTTP access log (fix #126) - #128
Merged
Merged
Conversation
c2j
approved these changes
Aug 3, 2026
c2j
left a comment
Owner
There was a problem hiding this comment.
✅ LGTM — 建议先合并此 PR
验证结果
| 检查项 | 结果 |
|---|---|
cargo check --features serve |
✅ |
cargo fmt -- --check |
✅ |
cargo clippy --features serve |
✅ (无新增告警) |
| access_log 单测 | ✅ 6/6 |
| 集成测试 serve_api | ✅ 8/8 |
代码评审
Apache CLF 格式正确性: ✅
%h %l %u [%t] "%r" %>s %b "%{Referer}i" "%{User-agent}i" + 自定义 <latency>ms
验证输出:
127.0.0.1 - - [03/Aug/2026:17:07:56 +0800] "GET /api/v1/stats HTTP/1.1" 200 - "-" "-" 0ms
127.0.0.1 - - [03/Aug/2026:17:07:56 +0800] "GET /api/v1/nope-not-a-route HTTP/1.1" 404 - "-" "-" 0ms
- CLF 时间戳
%d/%b/%Y:%H:%M:%S %z→03/Aug/2026:17:07:56 +0800✅ - HTTP 版本动态渲染 (0.9~3) ✅
- 404 请求正确记录(middleware ordering fix 有效)✅
chrono 依赖引入: ✅ 作为 optional feature 添加,不影响其他 feature 编译
Middleware ordering fix: ✅ fallback 移到 layer(middleware) 之前,确保 404 请求经过 access log
合并注意事项
因 #127 也修改 handlers.rs 和 tests/serve_api.rs,两个 PR 存在冲突。建议先合并此 PR,然后 #127 rebase 到 main 后重新验证。
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.
#126 serve: HTTP 访问日志格式不标准
改动
src/server/access_log.rs— 访问日志改为标准 Apache Combined Log Format:实际输出示例:
%t使用 CLF[dd/MMM/yyyy:HH:mm:ss +zzzz],含正确时区偏移(替代原先无时区、手写 UTC 时钟)%r渲染真实 HTTP 版本(HTTP/1.1 / HTTP/2 …),不再硬编码 HTTP/1.1-)chrono(仅servefeature,optional)src/server/handlers.rs— 修复 axum 层顺序 bug:.fallback(serve_asset)之前加在.layer(middleware)之后,导致 404(含 SPA/asset 兜底)请求完全绕过访问日志中间件。把.fallback()移到.layer()之前后,所有请求都会经过日志。tests/serve_api.rs— 新增回归断言:404(fallback 处理)请求必须出现在http.log。验证
cargo build --features serve/--features fullcargo fmt -- --checkcargo clippy --features serve(涉及文件)cargo test --features serve --test serve_apicargo test --features full全量import::parser::tests::test_path_mapping_applied,本改动未触碰该文件)说明
<latency>ms为 serve: HTTP 访问日志格式不标准 #126 要求保留的扩展;GoAccess / AWStats / Logstash 默认正则需一行自定义配置(字段提取类工具如 Apache/Splunk/ELK Search 开箱可用)。AGENTS.md改动。