Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error_log message is truncated when using print_r

Tags:

php

I'm not experienced in PHP and I'm, using:

error_log("big array:" . print_r($bigArray, true));

to look at what's inside a big array but it looks like the output is cut off before I get to the interesting stuff in the output like so:

...
           [4] => Array
            (
                [id] => 100039235
                [start] => 11:00
                [end] => 19:00
                [punches] => Array
                    (
                        [0] => Array
                            (
                                [id] => 6319
                                [comment] => 

Is this expected? Are there other ways or workarounds to get more of the array logged out?

like image 501
Cotten Avatar asked Sep 02 '14 10:09

Cotten


1 Answers

If you check the error INI options in PHP you'll notice there's a log_errors_max_len option:

Set the maximum length of log_errors in bytes. In error_log information about the source is added. The default is 1024 and 0 allows to not apply any maximum length at all. This length is applied to logged errors, displayed errors and also to $php_errormsg.

When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

Hence, if you want to use error_log to output these huge messages, make sure you change log_errors_max_len to a large number (or 0 for unlimited length).

// Append to the start of your script
ini_set('log_errors_max_len', '0');
like image 93
h2ooooooo Avatar answered Oct 03 '22 02:10

h2ooooooo