【问题标题】:error_log not working as expectederror_log 未按预期工作
【发布时间】:2013-01-01 23:38:43
【问题描述】:

我有以下基本代码:

<?php

    //http://localhost/error_log.php
    echo "write to the error_log";
    error_log("error_log entry");
    //error_log("error_log entry",0);

?>

当我导航到此页面时,我在浏览器中看到write to the error_log。它甚至出现在 access_log /var/log/apache2/access.log

[my ip here] - - [18/Jan/2013:09:18:54 +0000] "GET /error_log.php HTTP/1.1" 200 314 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"

但是当我检查 error_log (即/var/log/apache2/error.log)时,我看不到任何一个 error_log 消息。

为什么这些没有被输入到 error_log 中?

【问题讨论】:

  • 行为取决于error_log 配置指令的设置。 ini_get('error_log') 说什么?

标签: php error-handling error-logging error-log


【解决方案1】:

error.log 不会记录任何内容,除非 error_log.php 页面出错。

access.log 记录 Apache Server 处理的所有事件

这就是您的error.log 不记录事件的原因

查看http://httpd.apache.org/docs/2.2/logs.html了解更多信息

【讨论】:

    【解决方案2】:

    你在没有第二个参数的情况下调用它,这意味着默认为 0

    0   message is sent to PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the error_log configuration directive is set to. This is the default option.
    

    现在它取决于configuration of error_log

    如果这里不是“stderr”,php不会登录到apache错误日志中。

    这个 php 的“syslog”接缝将您的日志消息发送到syslog

    现在这取决于您如何配置 rsyslog.d

    但是看看下面的日志

    tail /var/log/syslog
    tail /var/log/messages
    tail /var/log/php
    tail /var/log/php.log
    

    你的消息应该在其中之一。

    【讨论】:

      猜你喜欢
      • 2021-06-04
      • 2022-01-24
      • 2015-05-11
      • 2020-05-15
      • 2014-10-31
      • 2018-02-12
      • 2014-01-20
      • 2015-01-13
      • 2013-08-01
      相关资源
      最近更新 更多