Skip to content

Commit

Permalink
Adding a 'reopen' configuration parameter to the syslog handler.
Browse files Browse the repository at this point in the history
When enabled, the syslog connection will be reopened for every log event.
This allows the calling application to call openlog() itself without changing
the Log handler's behavior.

Request: 18185
  • Loading branch information
jparise committed Feb 16, 2011
1 parent 26b8992 commit bb3bc0c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
16 changes: 13 additions & 3 deletions Log/syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class Log_syslog extends Log
*/
var $_inherit = false;

/**
* Should we re-open the syslog connection for each log event?
* @var boolean
* @access private
*/
var $_reopen = false;

/**
* Maximum message length that will be sent to syslog(). If the handler
* receives a message longer than this length limit, it will be split into
Expand Down Expand Up @@ -83,6 +90,9 @@ function Log_syslog($name, $ident = '', $conf = array(),
$this->_inherit = $conf['inherit'];
$this->_opened = $this->_inherit;
}
if (isset($conf['reopen'])) {
$this->_reopen = $conf['reopen'];
}
if (isset($conf['maxLength'])) {
$this->_maxLength = $conf['maxLength'];
}
Expand All @@ -108,7 +118,7 @@ function Log_syslog($name, $ident = '', $conf = array(),
*/
function open()
{
if (!$this->_opened) {
if (!$this->_opened || $this->_reopen) {
$this->_opened = openlog($this->_ident, LOG_PID, $this->_name);
}

Expand Down Expand Up @@ -154,8 +164,8 @@ function log($message, $priority = null)
return false;
}

/* If the connection isn't open and can't be opened, return failure. */
if (!$this->_opened && !$this->open()) {
/* If we need to (re)open the connection and open() fails, abort. */
if ((!$this->_opened || $this->_reopen) && !$this->open()) {
return false;
}

Expand Down
4 changes: 4 additions & 0 deletions docs/guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,10 @@ Configuration
| | | | process, or start a new |
| | | | one via `openlog()`_? |
+-------------------+-----------+---------------+---------------------------+
| ``reopen`` | Boolean | false | Reopen the syslog |
| | | | connection for each log |
| | | | event? |
+-------------------+-----------+---------------+---------------------------+
| ``maxLength`` | Integer | 500 | Maximum message length |
| | | | that will be sent to the |
| | | | `syslog()`_ function. |
Expand Down
1 change: 1 addition & 0 deletions package.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$version = '1.12.6';
$notes = <<<EOT
- Improved the console handler's stream handling. (Bug 17874)
- Added a 'reopen' configuration parameter to the syslog handler. (Request 18185)
EOT;

$package = new PEAR_PackageFileManager2();
Expand Down
8 changes: 5 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<email>jan@horde.org</email>
<active>yes</active>
</lead>
<date>2010-12-23</date>
<time>15:21:49</time>
<date>2011-02-15</date>
<time>21:11:28</time>
<version>
<release>1.12.6</release>
<api>1.0.0</api>
Expand All @@ -38,6 +38,7 @@
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT License</license>
<notes>
- Improved the console handler&apos;s stream handling. (Bug 17874)
- Added a &apos;reopen&apos; configuration parameter to the syslog handler. (Request 18185)
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -148,10 +149,11 @@
<release>stable</release>
<api>stable</api>
</stability>
<date>2010-12-23</date>
<date>2011-02-15</date>
<license uri="http://www.opensource.org/licenses/mit-license.php">MIT License</license>
<notes>
- Improved the console handler&apos;s stream handling. (Bug 17874)
- Added a &apos;reopen&apos; configuration parameter to the syslog handler. (Request 18185)
</notes>
</release>
<release>
Expand Down

0 comments on commit bb3bc0c

Please sign in to comment.