简体   繁体   English

LOG4PHP文件大小错误

[英]LOG4PHP File size Error

I am running this script as a cron job on GoDaddy Shared Hosting (php 5.3.13), and am using log4php. 我正在GoDaddy共享主机(php 5.3.13)上将其作为cron作业运行,并且正在使用log4php。 The script seems to run fine, and finish. 该脚本似乎可以正常运行并完成。 But then when log4php tries to finish up, it throws this error. 但是,当log4php尝试完成时,它将引发此错误。

It does seem to actually output the file, and its contents. 它似乎确实输出了文件及其内容。 And I even changed the file's permissions to 777. It seems to be throwing this error when it does the filesize check... 而且我什至将文件的权限更改为777。在执行文件大小检查时,似乎正在抛出此错误...

Any help with the cause/solution to this error would be much appreciated. 对此错误的原因/解决方案的任何帮助将不胜感激。

Error: 错误:

<b>Fatal error</b>: Uncaught exception 'ErrorException' with message '2: filesize() [&lt;a href='function.filesize'&gt;function.filesize&lt;/a&gt;]: stat failed for log.txt, file: /home/content/89/10338789/html/Forum/phpBB3/program/log4php/appenders/LoggerAppenderRollingFile.php, line: 223' in /home/content/89/10338789/html/Forum/phpBB3/program/log4php/appenders/LoggerAppenderRollingFile.php:223
Stack trace:
#0 [internal function]: errorHandler(2, 'filesize() [&lt;a ...', '/home/content/8...', 223, Array)
#1 /home/content/89/10338789/html/Forum/phpBB3/program/log4php/appenders/LoggerAppenderRollingFile.php(223): filesize('log.txt')
#2 /home/content/89/10338789/html/Forum/phpBB3/program/log4php/appenders/LoggerAppenderFile.php(165): LoggerAppenderRollingFile-&gt;write(NULL)
#3 /home/content/89/10338789/html/Forum/phpBB3/program/log4php/LoggerAppender.php(85): LoggerAppenderFile-&gt;close()
#4 [internal function]: LoggerAppender-&gt;__destruct()
#5 {main}
thrown in <b>/home/content/89/10338789/html/Forum/phpBB3/program/log4php/appenders/LoggerAppenderRollingFile.php</b> on line <b>223</b><br />

Configuration File: 配置文件:

<configuration xmlns="http://logging.apache.org/log4php/">

    <appender name="myConsoleAppender" class="LoggerAppenderConsole">
        <filter class="LoggerFilterLevelRange">
            <param name="levelMin" value="info" />
        </filter>
    </appender>

    <appender name="myFileAppender" class="LoggerAppenderRollingFile">
        <layout class="LoggerLayoutPattern">
            <param name="conversionPattern" value="%date %-5level - %message%newline" />
        </layout>
        <param name="file" value="log.txt" />
        <param name="maxFileSize" value="10MB" />
    </appender>

    <appender name="myEmailAppender" class="LoggerAppenderMail">
        <layout class="LoggerLayoutSimple" />
        <param name="to" value="jonathonwisnoski@hotmail.com" />
        <param name="from" value="logger@xxx.ca" />
        <filter class="LoggerFilterLevelRange">
            <param name="levelMin" value="info" />
        </filter>
    </appender>

    <root>
        <appender_ref ref="myConsoleAppender" />
        <appender_ref ref="myFileAppender" />
        <appender_ref ref="myEmailAppender" />
    </root>
</configuration>

...or you change the erroneous code line in LoggerAppenderRollingFile.php to: ...或者您将LoggerAppenderRollingFile.php中的错误代码行更改为:

if (filesize(realpath($this->file)) > $this->maxFileSize) {

http://php.net/manual/en/function.realpath.php http://php.net/manual/zh/function.realpath.php

It's an LoggerAppenderRollingFile issue, you need to use the absolute path to log file (workaround). 这是LoggerAppenderRollingFile问题,您需要使用绝对路径来记录文件(解决方法)。 After script execution the LoggerAppender::__destruct is called and the relative file log (log.txt) cannot be found. 执行脚本后,将调用LoggerAppender :: __ destruct,并且找不到相对文件日志(log.txt)。

change: 更改:

log4php.appender.<yourappender>.file=log.txt 

to

log4php.appender.<yourappender>.file=/absolutepath/log.txt

Releated topics: 相关主题:

  1. http://www.php.net/manual/en/function.register-shutdown-function.php#92657 http://www.php.net/manual/zh/function.register-shutdown-function.php#92657
  2. Why does getcwd() returns / in __destruct()? 为什么getcwd()在__destruct()中返回/?
  3. https://bugs.php.net/bug.php?id=34206 https://bugs.php.net/bug.php?id=34206

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

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