为什么此log4php配置会导致在日志文件中输出重复项



我有log4php config,其中包含其特定文件中每个级别的附录:

<configuration xmlns="http://logging.apache.org/log4php/">
    <appender name="info" class="LoggerAppenderRollingFile">
        <layout class="LoggerLayoutPattern">
            <param name="conversionPattern" value="%date %logger %-5level %msg%n"/>
        </layout>
        <param name="file" value="../app/logs/info.log"/>
        <param name="append" value="true"/>
        <param name="maxFileSize" value="100MB"/>
        <param name="maxBackupIndex" value="1"/>
        <filter class="LoggerFilterLevelRange">
            <param name="levelMin" value="info"/>
            <param name="levelMax" value="info"/>
        </filter>
    </appender>
    <appender name="warn" class="LoggerAppenderRollingFile">
        <layout class="LoggerLayoutPattern">
            <param name="conversionPattern" value="%date %logger %-5level %msg%n"/>
        </layout>
        <param name="file" value="../app/logs/warn.log"/>
        <param name="append" value="true"/>
        <param name="maxFileSize" value="100MB"/>
        <param name="maxBackupIndex" value="1"/>
        <filter class="LoggerFilterLevelRange">
            <param name="levelMin" value="warn"/>
            <param name="levelMax" value="warn"/>
        </filter>
    </appender>
    <appender name="error" threshold="error" class="LoggerAppenderRollingFile">
        <layout class="LoggerLayoutPattern">
            <param name="conversionPattern" value="%date %logger %-5level %msg%n"/>
        </layout>
        <param name="file" value="../app/logs/error.log"/>
        <param name="append" value="true"/>
        <param name="maxFileSize" value="100MB"/>
        <param name="maxBackupIndex" value="1"/>
        <filter class="LoggerFilterLevelRange">
            <param name="levelMin" value="error"/>
            <param name="levelMax" value="fatal"/>
        </filter>
    </appender>
    <appender name="debug" class="LoggerAppenderRollingFile">
        <layout class="LoggerLayoutPattern">
            <param name="conversionPattern" value="%date %logger %-5level %msg%n"/>
        </layout>
        <param name="file" value="../app/logs/debug.log"/>
        <param name="append" value="true"/>
        <param name="maxFileSize" value="100MB"/>
        <param name="maxBackupIndex" value="1"/>
        <filter class="LoggerFilterLevelRange">
            <param name="levelMin" value="debug"/>
            <param name="levelMax" value="debug"/>
        </filter>
    </appender>
    <root>
        <level value="debug" />
        <appender-ref ref="info"/>
        <appender-ref ref="warn"/>
        <appender-ref ref="error"/>
        <appender-ref ref="debug"/>
    </root>
</configuration>

和以下PHP代码:

Logger::configure('config.xml');
$logger = Logger::getRootLogger();
$logger->warn("test");
$logger->error("test");
$logger->info("test");
$logger->debug("test");

,当我运行PHP代码时,每个文件都是创建的,并按预期按级别为每个文件编写日志,但是每个日志行都像这样重复:

cat logs/info.log 
2017-10-01T22:06:44+00:00 root INFO  test
2017-10-01T22:06:44+00:00 root INFO  test

我在做什么错?

更新

也尝试了独白记录仪,但遇到了同样的问题,看起来类负载有问题。我正在使用config的作曲家:

{
  "require": {
    "monolog/monolog": "1.23.0"
  },
  "autoload": {
    "psr-4": {
      "App\": "src"
    }
  }
}

我有HTACCESS将流量重定向到索引PHP,在那里我初始化了应用程序类(不在SRC中)。在那个课程中,我只是下一个代码:

$this->logger = new Logger('default');
$this->logger->pushHandler(new StreamHandler(LOGS_DIR . 'info.log', Logger::INFO));
$this->logger->pushHandler(new StreamHandler(LOGS_DIR . 'error.log', Logger::ERROR));
$this->logger->pushHandler(new StreamHandler(LOGS_DIR . 'debug.log', Logger::DEBUG));
$this->logger->error("error");
$this->logger->info("info");
$this->logger->debug("debug");

我的使用方式可能有问题?

所以在我的特殊情况下,我有错误的.htaccess文件,它不仅会加载我需要的页面,还加载了诸如favico.php。

之类的页面

之前:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9/^.]+)$ index.php [QSA,L]

之后:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ index.php [QSA,L]

只是更改了不包含点的匹配路由的模式。

相关内容

  • 没有找到相关文章

最新更新