I'm sending some rather long stack traces to the apache error log using php's 'error_log()' and the entries are getting truncated. I have not found a way to make entries longer. Any ideas?
As Leopoldo said, setting log_errors_max_len
seems pretty useless in this situation, and PHP manual states this clearly.
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
).
The default limit on the maximum length of error message passing through error_log() is 1024 bytes.
Detailed information there http://www.php.net/manual/en/errorfunc.configuration.php#ini.log-errors-max-len
As Leopoldo said, setting log_errors_max_len
seems pretty useless in this situation, and PHP manual states this clearly.
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
).
PHP Manual says about the settings log_errors_max_len
in php.ini:
Set the maximum length of log_errors in bytes. (...) The default is 1024 and 0 allows to not apply any maximum length at all.
Some suggest that you can change it doing for example:
ini_set("log_errors_max_len", 2048);
But the Manual adds:
This length is applied to logged errors, displayed errors and also to $php_errormsg, but not to explicitly called functions such as error_log().
I'm trying to find a solution. Will edit if I do.
Reading the question above made me wonder if the problem is within Apache. Yes, the truncation occurs within PHP for Apache will allow even over 10,000 characters. Here's a Perl script assessing Apache's ability to post long error messages into its log:
#!/usr/bin/perl -w
#
# Test error log length limitations
# Result: no limitation
#
#
use strict;
use CGI;
my $query = CGI->new;
print $query->header;
print "<html><body>You have reached "
."cgi-bin/admin/test_error_log.pl"
."</body></html>\n";
print STDERR "This is an error message from $0\n";
print STDERR "
[Above should be a blank line] here is a multiline error message
here is the third and final line of it\n";
print STDERR 'abcde' x 200; #1,000 characters
print STDERR "\nAbove is 1,000 characters of output of 'abcde'\n";
print STDERR 'vwxyz' x 2000; #10,000 characters
print STDERR "\nAbove is 10,000 characters of output of 'vwxyz'\n";
ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M"
This configuration will rotate the error logfile whenever it reaches a size of 5 megabytes, and the suffix to the logfile name will be created of the form errorlog.YYYY-mm-dd-HH_MM_SS.
For more read official documentation from apache.org Link Here
© 2022 - 2024 — McMap. All rights reserved.