PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Logging » Log » Bug #5273

E_WARNING generated when opening log file

Details

Submitted2005-09-02 03:58 UTC
Fromoracle dot shinoda at gmail dot com
Assignedjon
StatusClosed
PackageLog
PHP Version4.4.0
OSLinux (Debian)
Roadmaps(Not assigned)

Comments

[2005-09-02 03:58 UTC] oracle dot shinoda at gmail dot com

Description:
------------
Using Log 1.8.7. In method open() in Log/file.php, there is an attempt to chmod the newly-opened log file:

/* Attempt to set the log file's mode. */
@chmod($this->_filename, $this->_mode);

Sure, if it doesn't work, the @ suppresses error _output_. But it doesn't stop the fact that the error _occured_.

What this means in my case is, I have a function that is my error handler (registered with set_error_handler()), and it gets called when that line is executed, because PHP doesn't have permissions to chmod it.

My error function doesn't know about the @, and so blithely goes ahead and does it's business (in my case, killing the script).

I suggest that there be an attempt at checking if the chmod operation be allowed first, as a backstop. I changed the lines above (around line 207) to the following:

/* Attempt to set the log file's mode. */
if (is_writable(dirname($this->_filename))) {
@chmod($this->_filename, $this->_mode);
}

Of course, the check may not be the best, but it works for me.

Test script:
---------------
<?php
set_error_handler('error');
function error ($code, $message, $file, $line, $vars)
{
// Does various stuff
exit(1);
}

require_once 'Log.php';
$log =& Log::factory('file', '/var/log/apache/the.log');

// trigger a log write somehow

?>

Expected result:
----------------
No error.

Actual result:
--------------
Script exits, because error() was called.