如何简化nginx错误日志?

我想简化nginx错误日志,但没有成功。 我正在执行index.php这个:

error_log('abc'); 

我得到这个错误:

 2016/08/22 16:11:57 [error] 5267#0: *4 FastCGI sent in stderr: "PHP message: abc" while reading response header from upstream, client: 192.168.1.12, server: domain.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "domain.com", referrer: "http://domain.com/" 

一边看着nginx的错误文件:

 tail -f /var/log/nginx/error.log 

我试图编辑/etc/nginx/nginx.conf +添加

 log_format vhosts 'test'; 

在http {section中,但是错误信息仍然是一样的。 我想在error.log文件中只获取“abc”。

谢谢

log_formataccess_log 。 就像是:

 tail -f /var/log/nginx/error.log | awk '{print $12}' 

可以做的伎俩,但只有“abc”是一个非空白string。

你不能像这样简化错误日志。

nginx通过nginx和应用服务器软件之间使用的FastCGI接口(这里是PHP)接收错误信息。

2016/08/22 16:11:57 [error] 5267#0: *4 FastCGI sent in stderr:是nginx写入error.log以指示时间戳的部分,以下错误消息来自FastCGI接口。

"PHP message: abc"是PHP本身发送的消息。

while reading response header from upstream, client: 192.168.1.12, server: domain.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "domain.com", referrer: "http://domain.com/"是nginx添加的,用来表示有关错误的其他信息。

message_type设置为3时,您可以使用PHP error_log()函数的$destination参数将错误写入日志文件。但是,这可能包含除精确testing之外的其他文本。 在这种情况下,您可以随时打开一个新文件并通过PHP写入。 也许你想实现你自己的日志loggingfunction。