1

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="[email protected]" />
        <param name="from" value="[email protected]" />
        <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>
0

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

2 Comments

Indeed, the bug (issues.apache.org/jira/browse/LOG4PHP-210) is fix on "develop". Checkout the commit but this version isn't released yet... for 4 years.
I was doubtful but it really worked, as it is anyways on my local copy and I am free to make a change on the source code. Thank you. I think the log4php is not under active development and hence the fixes were not promoted to the mainstream/release candidate yet.
6

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

1 Comment

If you don't want to hardcode a path, this seems to work: %APP_PATH%/application/logs/debug.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.