PEAR is archived and read-only

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

Home » Logging » Log » Bug #9822

using syslog "steals" the apache error logging if it uses syslog

Details

Submitted2007-01-14 00:52 UTC
Fromcbs at cts dot ucla dot edu
Assignedjon
StatusClosed
PackageLog
PHP Version5.2.0
OSlinux
Roadmaps(Not assigned)

Comments

[2007-01-14 00:52 UTC] cbs at cts dot ucla dot edu

Description:
------------
I'm using php with apache. I have apache configured to use syslog for all error logging.

If I use PEAR Log to syslog, the openlog() call in Log/syslog.php steals the syslog stream from apache by re-opening the syslog ouput and re-directs all of the apache errors to the log file just opened.

Test script:
---------------
In apache/conf/httpd.conf set "errlog syslog:local0"

Then something like:

<?php

include_once 'Log.php';
$log = &Log::singleton('syslog', LOG_LOCAL1, 'test');
$log->log("test", PEAR_LOG_DEBUG);

?>

Run that, then in apache try to load a non-existant page. The apache error gets logged to local1 instead of local0

The fix is to change Log/syslog.php to not use openlog(). Remove the open() call completely (or change it to always return true).

Change log() so that

if (!syslog($this->_toSyslog($priority), $message)) {
return false;
}

is instead

if (!syslog($this->_name|$this->_toSyslog($priority), $message)) {
return false;
}

Using OR to combine the logname and loglevel sends the output to the correct file, and doesn't break apache because openlog() isn't called.

Expected result:
----------------
The apache error log should always go to local0; the PEAR Log output should always go to local1

Actual result:
--------------
Once openlog() from Log/syslog.php is called, all output from apache and PEAR Log goes to local1

[2007-01-14 23:39 UTC] cbs at cts dot ucla dot edu

I believe that whenever you call openlog() it resets all of the logging parameters (ident, options, and facility). Once PEAR Log/syslog calls openlog(), all apache error messages end up going to the php syslog file, with the ident and options specified as above.

Occasionally, I see things in the apache error log. I'm guessing that happens when apache spawns off a new process that would call openlog() after forking.

What about using the $conf array when creating a new Log/syslog to determine whether or not open() should do anything?

Something like this:

--- syslog.php~ 2007-01-14 15:30:32.000000000 -0800
+++ syslog.php 2007-01-14 15:32:11.000000000 -0800
@@ -49,6 +49,7 @@
$this->_name = $name;
$this->_ident = $ident;
$this->_mask = Log::UPTO($level);
+ $this->_use_openlog = isset($conf['use_openlog']);
}

/**
@@ -58,6 +59,7 @@
*/
function open()
{
+ if ($this->_use_openlog == false) return true;
if (!$this->_opened) {
openlog($this->_ident, LOG_PID, $this->_name);
$this->_opened = true;
@@ -72,6 +74,7 @@
*/
function close()
{
+ if ($this->_use_openlog == false) return true;
if ($this->_opened) {
closelog();
$this->_opened = false;
@@ -113,7 +116,10 @@
/* Extract the string representation of the message. */
$message = $this->_extractMessage($message);

- if (!syslog($this->_toSyslog($priority), $message)) {
+ $prio = $this->_toSyslog($priority);
+ if ($this->_use_openlog == false) $prio |= $this->_name;
+
+ if (!syslog($prio, $message)) {
return false;
}