Files
cursor/plans/webmanlog-4a3bab11.plan.md
ray zhou 2dd9f17da9 ok
2026-06-29 14:51:55 +08:00

4.2 KiB
Raw Permalink Blame History


todos:

  • id: "disable-webman-log" content: "在 config/plugin/webman/log/app.php 将 enable 设为 false或接 WEBMAN_LOG_ENABLE 环境变量)" status: pending
  • id: "restart-webman" content: "docker exec 内执行 php webman restart 使配置生效" status: pending
  • id: "verify-logs" content: "验证 SeasLog/LoggerService 仍写入 runtime/logs/{worker}/,且 webman.log 不再出现 [Redis] 请求块" status: pending isProject: false

关闭 webman/log middleware 对业务日志的影响

结论(直接回答)

不会影响你本身的业务日志。
config/plugin/webman/log/middleware.php 注册的是插件自带的 Webman\Log\Middleware,与业务代码里的 LoggerServiceLogMiddleware 是两套独立机制。


slot_pwa 里实际有三套日志

flowchart LR
    subgraph business [业务日志_不受影响]
        LoggerService --> SeasLog
        SeasLog --> runtime_logs_worker["runtime/logs/{worker}/"]
    end

    subgraph monolog [Monolog_不受影响]
        SupportLog["support\\Log / Log::debug"] --> config_log["config/log.php"]
        config_log --> webman_log_file["runtime/logs/webman.log"]
        config_log --> log_log_file["runtime/logs/log.log"]
    end

    subgraph plugin [webman/log插件_关闭后停止]
        WebmanLogMW["Webman\\Log\\Middleware"] --> SupportLogDefault["Log::channel default"]
        WebmanLogMW --> auto["自动记录 IP/URL/POST/SQL/Redis"]
    end
日志来源 配置/入口 写入位置 关 webman/log 后
LoggerService(主力) app/service/LoggerService.php + app/AppBootStrap.php 初始化 SeasLog runtime/logs/{worker_name}/ 正常
LogMiddlewaretraceId config/middleware.phpapi/gasea 路由 只初始化 traceId业务 log 大多已注释 正常
support\Log / Monolog config/log.php webman.log / log.log 正常(你主动 Log::info() 仍会写)
webman/log 插件 config/plugin/webman/log/middleware.php 同上 default 通道 → webman.log 停止自动请求汇总

你看到的 [Redis] Redis::hincrby('prometheus:...') 属于最后一行:插件在每个请求结束时自动拼接 Redis/SQL,不是 LoggerService 打的。


关闭后会失去什么

仅失去 webman/log 自动请求日志,典型内容:

  • 请求行:IP METHOD URL [xxms] [webman/log]
  • [POST] 请求体
  • [SQL] / [Redis] 本请求内所有命令(含 Prometheus 的 hincrby
  • 经插件捕获的异常堆栈(写入同一请求日志块)

官方说明:插件不替代 webman 内核日志;未捕获异常仍可能由框架异常处理单独记录。

关闭后会失去的一个「副作用」能力

Webman\Log\Middleware 还会在请求结束检测 未提交的数据库事务rollBack + 抛 RuntimeException。关掉插件后这条开发期保护也会消失(与业务 LoggerService 无关,但排障时需注意)。


推荐关闭方式(不要直接删 middleware.php

Webman 加载插件配置时,若同目录 config/plugin/webman/log/app.phpenable => false,会跳过 middleware.php 的加载(见 Config::loadFromDir 逻辑)。

推荐:改 app.php,而不是删/清空 middleware.php

'enable' => false,

或按环境控制(与现有 DEBUG 类似):

'enable' => filter_var(getenv('WEBMAN_LOG_ENABLE'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false,

改完后需 restart webman 生效。


验证清单(关闭后自测)

  1. 触发一条业务接口,确认 runtime/logs/{worker}/ 下 SeasLog 仍有 LoggerService 输出
  2. 确认 runtime/logs/webman.log 不再出现 [Redis] / [webman/log] 请求块
  3. 故意打一条 LoggerService::error()Log::error(),确认仍写入对应文件
  4. 异常接口:确认业务异常处理与 SeasLog 错误日志仍正常