如何打印调试日志? [英] How to print a debug log?

查看:595
本文介绍了如何打印调试日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试一些PHP代码,但是我想将日志打印到屏幕或文件上对我来说很好.

I'd like to debug some PHP code, but I guess printing a log to screen or file is fine for me.

如何打印PHP代码中的日志?

通常的print/printf似乎是HTML输出而不是控制台输出.

The usual print/printf seems to go to HTML output not the console.

我让Apache服务器执行PHP代码.

I have Apache server executing the PHP code.

推荐答案

一个鲜为人知的技巧是mod_php将stderr映射到Apache日志.并且,有一个流,因此file_put_contents('php://stderr', print_r($foo, TRUE))会很好地将$foo的值转储到Apache错误日志中.

A lesser known trick is that mod_php maps stderr to the Apache log. And, there is a stream for that, so file_put_contents('php://stderr', print_r($foo, TRUE)) will nicely dump the value of $foo into the Apache error log.

这篇关于如何打印调试日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆