Pregunta

I am running this script as a cron job on GoDaddy Shared Hosting (php 5.3.13), and am using log4php. The script seems to run fine, and finish. But then when log4php tries to finish up, it throws this error.

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...

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>
¿Fue útil?

Solución 2

It's an LoggerAppenderRollingFile issue, you need to use the absolute path to log file (workaround). After script execution the LoggerAppender::__destruct is called and the relative file log (log.txt) cannot be found.

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
  2. Why does getcwd() returns / in __destruct()?
  3. https://bugs.php.net/bug.php?id=34206

Otros consejos

...or you change the erroneous code line in LoggerAppenderRollingFile.php to:

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

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top