How to make apache error log entries longer
Asked Answered
A

5

11

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?

Androsterone answered 13/6, 2012 at 18:59 Comment(1)
Please consider changing the accepted answer to be kumade's answer.Undershot
B
6

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).

Biedermeier answered 7/4, 2017 at 15:4 Comment(1)
Thanks for this. I fail to see their logic in the function truncating the message for the configured error log file entries but not for those in a custom path.Undershot
T
8

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

Trey answered 13/6, 2012 at 19:15 Comment(0)
B
6

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).

Biedermeier answered 7/4, 2017 at 15:4 Comment(1)
Thanks for this. I fail to see their logic in the function truncating the message for the configured error log file entries but not for those in a custom path.Undershot
F
3

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.

Froissart answered 9/1, 2017 at 19:48 Comment(0)
F
1

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";
Fanchette answered 3/12, 2014 at 21:48 Comment(1)
I have the same problem with Nginx.Froissart
H
-3
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

Highstepper answered 13/6, 2012 at 19:13 Comment(2)
-1 I'm not sure why this is an accepted answer. This won't do anything to prevent truncation of individual entries in the log.Cahilly
This will actually truncate long logs because it is restrained by the OS' pipe length limit.Eward

© 2022 - 2024 — McMap. All rights reserved.