Skip to content

v0.7.0 - 结构化日志管线重构

Choose a tag to compare

@sllhSmile sllhSmile released this 16 Sep 06:14
· 8 commits to main since this release

主要变更

  • 重构 RequestContext:统一 request ID 与开始时间的生成和查询,使用固定协程 Context key,并提供 id()、startTime() 等无副作用查询方法。
  • 重构四类日志采集器:API、Guzzle、数据库和 Redis 共用 CollectorLogger、统一日志结构及异常隔离。
  • 新增 schema_version 1 的 StructuredJsonFormatter,时间戳固定为北京时间微秒格式,并避免普通同名消息被误判为采集器日志。
  • 新增递归字段脱敏、容量限制及 payload_protection 元数据;显式无效 JSON 采用 fail-closed 策略。
  • 安全快照 PSR-7 Stream:恢复可回绕流位置,支持 Hyperf SwooleStream,并跳过真正不可回绕的流。
  • Guzzle 仅负责 request ID 透传和 SDK 日志,不再设置 timeout、connect_timeout 或 swoole 参数。
  • trace_log.logger_channel 统一选择已有的 Hyperf Logger channel;不再要求在 logger.php 重复配置 apilog、sdklog、dblog、redislog alias。
  • 增加 PHPStan level 8、PHP-CS-Fixer 和 GitHub Actions CI。

兼容性与迁移

这是破坏性版本,要求 PHP >= 8.2、Hyperf ^3.2、Guzzle ^7.0。

  • RequestContext 移至 Sllhsmile\HyperfLog\Context 命名空间。
  • TraceContextData 更名为 TraceContext。
  • CustomizeJsonFormatter 更名为 StructuredJsonFormatter。
  • 采集器开关与 response_enabled 移至 trace_log.collectors。
  • 使用 trace_log.logger_channel 选择现有 Logger channel;null 表示跟随 logger.default。
  • 移除可配置 Context key、Guzzle 开始时间 Header 和公共超时配置。
  • PayloadProcessorInterface::process() 首个参数改为 Collector 枚举。

修复

  • 修复 Hyperf 默认 SwooleStream 请求体和响应体无法记录的问题。
  • 修复普通业务 message 为 http.server、http.client 等值时被错误分类并丢失 message 的问题。
  • Redis AUTH 始终遮蔽,日志处理或 Handler 异常不再影响业务结果。

验证

  • PHPUnit:44 tests,136 assertions
  • PHPStan level 8:通过
  • PHP-CS-Fixer:通过
  • Composer validate:通过
  • 宿主 Hyperf LoggerFactory 集成验证:通过