8

I'm not experienced in PHP and I had problems logging out big arrays using error_log and print_r.

I was told here to change the log_errors_max_len of the php.ini file and I went ahead and did a <?php phpinfo(); ?> to see where the php.ini file was loaded from. Then I changed it to log_errors_max_len = 0 but still the output is truncated.

I'm also using Laravel.

Anybody has any idea why this is not working? (I already restarted apache :)

Community
  • 1
  • 1
Cotten
  • 8,787
  • 17
  • 61
  • 98
  • Could you define big arrays? – Daan Sep 02 '14 at 11:52
  • 1
    I'm not really sure how big it is since the output is not showing the full array. It is nested with at least 4 levels. See example output here: http://stackoverflow.com/questions/25621252/error-log-message-is-truncated-when-using-print-r – Cotten Sep 02 '14 at 11:55
  • What does a var_dump give you? – Daan Sep 02 '14 at 11:56
  • It crashes the "Manager" class (part of a rest api) and me tailing application log or the apache error log gives no output. – Cotten Sep 02 '14 at 12:04
  • Let the var_dump stay and instead of running it in the browser run the script from (I'm guessing you use linux) linux terminal. – Daan Sep 02 '14 at 12:06
  • did your restarted the http service ? – JYoThI Apr 07 '17 at 14:53

3 Answers3

6

The main thing here, is that log_errors_max_len seems pretty useless in this situation. PHP manual states that:

This length is applied to logged errors, displayed errors and also to $php_errormsg, but not to explicitly called functions such as error_log()

The only solution I was able to find so far is to use:

error_log("Long error message...", 3, CUSTOM_LOG_FILE);

The second parameter of error_log() allows you to redirect message to a custom file. So, the last parameter should be a path to a custom log file.

This way I'm getting full error message and, what might be more important for someone, non ASCII characters are clearly readable there (not sure though, might be my bad, but when I'm logging them with standard log file - I get things like \xd0\xbf).

kumade
  • 541
  • 2
  • 9
  • 18
0

Make sure to set the configuration at the top of your page like this.

<?php
ini_set("log_errors_max_len", 0);
?>

See also this question. Might it be the issue you have?

Community
  • 1
  • 1
JustCarty
  • 3,839
  • 5
  • 31
  • 51
0

My mistake was, I mixed up php script arguments and php interpreter arguments. This happened in an IDE, but could as well happen in command line.

Two different things:

php -d log_errors_max_len=0 index.php // Interpreter arguments

php index.php -d log_errors_max_len=0 // Script arguments

enter image description here

gvlasov
  • 18,638
  • 21
  • 74
  • 110