Mantis - Quercus
Viewing Issue Advanced Details
4178 minor always 08-12-10 11:37 04-04-13 19:06
domdorn  
nam  
normal  
closed 4.0.10  
fixed  
none    
none 4.0.36  
0004178: error_log not working correctly with files
It seems, that error_log is not working correctly when writing to files.
This is reported by a user, we need additional information on this.

File to look at:
modules/quercus/src/com/caucho/quercus/lib/ErrorModule.java

Current _guess_: The method only appends to files, so appending to a non existing file may fail on some Operating Systems.
We have to check if the error only happens when the destination file does not exist.

If you're experiencing this error, please comment on it and provide a testcase/testdata.



 errorLogTest.php [^] (352 bytes) 08-13-10 08:25
 errorLogTestResultPage.png [^] (51,032 bytes) 08-13-10 08:28
 fileSystemPicture.png [^] (85,046 bytes) 08-13-10 08:35
 permissions.png [^] (60,262 bytes) 08-13-10 08:37

Notes
(0004710)
kmoore4now   
08-13-10 08:26   
I've just uploaded our test php page that shows this condition.
(0004711)
kmoore4now   
08-13-10 08:29   
errorLogTestResultPage.png shows the result of executing the errorLogTest.php page. Note that the result indicates success.
(0004712)
kmoore4now   
08-13-10 08:32   
The WAR is deployed to Jboss 4.3.0.GA_CP02b102513 running on Mac OS X v10.5.8

The web.xml has this:

<servlet>
    <servlet-name>Quercus Servlet</servlet-name>
    <servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>

  
 
    <init-param>
      <param-name>ini-file</param-name>
      <param-value>WEB-INF/php.ini</param-value>
    </init-param>
    
    <!--
      Location of the license to enable php to java compilation.
    -->
    <init-param>
      <param-name>license-directory</param-name>
      <param-value>WEB-INF/licenses</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>Quercus Servlet</servlet-name>
    <url-pattern>*.php</url-pattern>
  </servlet-mapping>

php.ini has this:

error_log="/Users/kmoore/error_log"
(0004713)
kmoore4now   
08-13-10 08:35   
fileSystemPicture.png shows that the error_log file exists in the specified directory.
(0004714)
kmoore4now   
08-13-10 08:37   
permissions.png shows that the error_log file has write permissions for everyone.
(0004715)
kmoore4now   
08-13-10 08:48   
This is shown in the Jboss console window after executing the test page:

[INFO] [talledLocalContainer] 13 Aug 2010 08:23:50,894 ERROR [STDERR] Aug 13, 2010 8:23:50 AM com.caucho.quercus.lib.ErrorModule error_log
[INFO] [talledLocalContainer] WARNING: test error log message
(0004716)
kmoore4now   
08-13-10 09:09   
Here is the content of error_log after executing the test:

line 1kmoore-osx-2:~ kmoore$ pwd
/Users/kmoore
kmoore-osx-2:~ kmoore$ cat error_log
line 1kmoore-osx-2:~ kmoore$

( I had added "line 1" before running the test )
(0004717)
domdorn   
08-13-10 09:10   
According to
http://en.php.net/manual/en/function.error-log.php [^]

 message_type

    Says where the error should go. The possible message types are as follows:

    error_log() log types 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.
    1 message is sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used.
    2 No longer an option.
    3 message is appended to the file destination. A newline is not automatically added to the end of the message string.

as you don't specify the destination, the default target is the system log.

so, if you want to write to your error-logfile, do it like this

error_log("My message", 3, "/Users/kmoore/error_log");

I would suggest you to create your own error_logging method to abstract this method, so you have your own function, e.g.

function log($logMessage){
return error_log($logMessage, 3, "/Users/kmoore/error_log");
}

http://de.php.net/manual/en/errorfunc.configuration.php#ini.error-log [^]
the documentation of the php.ini error_log specifies where script errors should be logged to, meaning if you have a syntax error in your page or an uncatched exception or something like that.

please try the error_log method with the additional arguments mentioned.


I'm updating the issue to state "no change required". If you think thats not correct, please feel free to post again and I'll open it up.

(0004718)
domdorn   
08-14-10 03:57   
Reopening as of user request.

This test demonstrates the bug:

<?
$logfile = '/tmp/testlog';
ini_set('error_log',$logfile);

$oldSize = filesize($logfile);
error_log("test");
$newSize = filesize($logfile);

assert( $newSize > $oldSize );

?>

which works in
php -v
PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:03:45)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

but not in current quercus.

I assume this is the behavior you are expecting.
If not, please comment on this.
(0004730)
domdorn   
08-18-10 12:14   
fixed in svn r7412.

If you have access to resin's svn source, please try it out and give feedback.
(0006236)
nam   
04-04-13 19:06   
php/1811
php/1812

Fixed for 4.0.36.