You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让XDebug将日志条目发送至VS Code调试控制台窗口?

实现XDebug/PHP日志输出到VS Code DEBUG CONSOLE

可行,以下是两种实用方案:

方案1:通过XDebug转发PHP日志到调试客户端

修改Apache配置的php.ini文件,在[XDebug]区块中调整配置:

[XDebug]
zend_extension=xdebug
xdebug.mode=debug,develop  ; 新增develop模式,用于转发PHP错误/日志到客户端
xdebug.start_with_request=yes
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.client_host=192.168.1.10
xdebug.client_port=9003
xdebug.log=C:\xampp\apache\logs\xdebug.log
xdebug.log_level=7

修改后重启Apache,此时PHP的错误、警告以及error_log()生成的内容会被XDebug转发到VS Code的DEBUG CONSOLE面板。

方案2:让PHP将日志输出到stderr,由VS Code捕获

修改php.ini中的error_log配置,将日志输出目标改为标准错误流:

error_log="php://stderr"

重启Apache后,error_log()生成的日志会输出到Apache的stderr,VS Code的PHP调试器会自动捕获该输出并显示在DEBUG CONSOLE中。

注意:XDebug自身的日志(即xdebug.log文件中的内容)默认不会显示在DEBUG CONSOLE中,该日志主要用于排查XDebug本身的问题,一般无需转发到调试面板。

内容的提问来源于stack exchange,提问作者andynewman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 05:32:41