简体   繁体   English

如何使apache错误日志条目更长

[英]How to make apache error log entries longer

I'm sending some rather long stack traces to the apache error log using php's 'error_log()' and the entries are getting truncated. 我正在使用php的'error_log()'向apache错误日志发送一些相当长的堆栈跟踪,并且条目被截断。 I have not found a way to make entries longer. 我还没有办法让条目更长。 Any ideas? 有任何想法吗?

The default limit on the maximum length of error message passing through error_log() is 1024 bytes. 通过error_log()的错误消息的最大长度的默认限制是1024个字节。

Detailed information there http://www.php.net/manual/en/errorfunc.configuration.php#ini.log-errors-max-len 详细信息请访问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. 正如Leopoldo 所说 ,在这种情况下设置log_errors_max_len似乎毫无用处,PHP手册清楚地说明了这一点。

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. error_log()的第二个参数允许您将消息重定向到自定义文件。 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 ). 这样我得到完整的错误信息,对于某些人来说可能更重要的是,非ASCII字符在那里可以清楚地读取(不确定,可能是我的坏,但是当我用标准日志文件记录它们时 - 我得到了像\\xd0\\xbf这样的东西。

PHP Manual says about the settings log_errors_max_len in php.ini : PHP手册说明了php.ini中的 log_errors_max_len设置:

Set the maximum length of log_errors in bytes. 设置log_errors的最大长度(以字节为单位)。 (...) The default is 1024 and 0 allows to not apply any maximum length at all. (...)默认值为1024,0允许不应用任何最大长度。

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() . 此长度适用于记录的错误,显示的错误以及$ php_errormsg, 但不适用于显式调用的函数,如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. 阅读上面的问题让我想知道问题是否在Apache内部。 Yes, the truncation occurs within PHP for Apache will allow even over 10,000 characters. 是的,截断发生在PHP中,因为Apache将允许甚至超过10,000个字符。 Here's a Perl script assessing Apache's ability to post long error messages into its log: 这是一个Perl脚本,用于评估Apache将长错误消息发布到其日志中的能力:

#!/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. 此配置将在错误日志文件达到5兆字节大小时轮换该错误日志文件,并将创建日志文件名称的后缀,格式为errorlog.YYYY-mm-dd-HH_MM_SS。

For more read official documentation from apache.org Link Here 有关更多阅读来自apache.org 链接的官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM