I'm debugging some php code of an API, and for this I'm using syslog() to view my debug messages. The problem is that I want to get some usefull logs. For example, is something null or false? Normally I use var_dump() for this, but since I'm working with in an API, var_dump, f*%$s up the API output.
I tried doing syslog(LOG_ERR, var_dump($myVar));
, but to no avail.
Does anybody know how I can "pretty print" variables/arrays in the syslog?
var_dump()
does direct output. There's no provision for it to RETURN its formatted output, so you'll need to use output buffering:
ob_start();
var_dump($something);
syslog(LOG_ERROR, ob_get_clean());
Note that print_r()
does have an optional 2nd argument to force it to return instead of outputting:
syslog(LOG_ERROR, print_r($something, TRUE));
var_export()
和print_r()
可能会返回内容,而不是将其回显
If you are using the syslog primarily as a means to debug, instead of using var_dump
, why dont you just 'tail' the syslog by using
tail -f /var/log/syslog
You can grep
for any keyword by using
tail -f /var/log/syslog | grep MY_KEYWORD --line-buffered
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.