Search code examples
phpsyslogrsyslog

Making logging of arrays in syslog readable


For troubleshooting, I often wish to log arrays and/or objects and use something like syslog(LOG_INFO,'cmds: '.print_r($cmds_reply,1)); which produces the following output. My difficulty is reading the log with all the superfluous characters and whitespace. Is there a better way?

Nov  3 14:38:19 raspberrypi php: cmds: Array#012(#012    [46] => Array#012        (#012            [0] => sv#012            [1] => stdClass Object#012                (#012                    [name] => to#012                    [value] => 5#012                )#012#012        )#012#012)

Solution

  • What about array_walk and a custom printing function?