Issues

ZF-7603: Syslog writer facility should be long

Issue Type: Bug Created: 2009-08-15T02:48:24.000+0000 Last Updated: 2010-06-21T06:00:27.000+0000 Status: Resolved Fix version(s): - 1.10.6 (22/Jun/10)

Reporter: Péter Nagy (antronin) Assignee: Ramon Henrique Ornelas (ramon) Tags: - Zend_Log

Related issues: - ZF-10015

Attachments: - Zend_Log_Writer_Syslog.patch

Description

In Zend_Log_Writer_Syslog::facility is defined as string and it is sent to openlog() this way hence openlog()'s 3rd parameter should be long, choosen from the predefined PHP constans LOG*. I would recommend to use the string with constant($this->_facility) and document that user should specify the constant name to use if required.

So the patch:

<pre class="highlight">
    protected function _initializeSyslog()
    {
        self::$_lastApplication = $this->_application;
        self::$_lastFacility    = $this->_facility;
        openlog($this->_application, LOG_PID, cnstant($this->_facility));
    }

Comments

Posted by Péter Nagy (antronin) on 2009-08-16T03:40:48.000+0000

I made a typo in the code above ("cnstant" is "constant"). The last line should be:

<pre class="highlight">
openlog($this->_application, LOG_PID, constant($this->_facility));

Posted by Matthew Weier O'Phinney (matthew) on 2010-06-18T09:17:00.000+0000

Actually, by default, the $_facility parameter is defined to the value of the LOG_USER constant; it's not actually a string, though the docblock reports it as such. You can alter the facility using a setter, but the assumption is that you're passing in one of those constants.

I think one of two things need to happen: * The $facility property needs to be marked as an integer * setFacility() needs to check the value against the known LOG* constants.

I'll proceed with those changes.

Posted by Matthew Weier O'Phinney (matthew) on 2010-06-18T09:26:21.000+0000

Updated per my comment in both trunk and 1.10 release branch.

Posted by Ramon Henrique Ornelas (ramon) on 2010-06-18T17:21:10.000+0000

Correction called function in_array() r22459 merged in branch r22460.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-06-18T17:26:45.000+0000

Unittests missing

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-06-18T18:20:42.000+0000

Closing again since there's been a separate issue added for the tests (ZF-10015).

Posted by Ramon Henrique Ornelas (ramon) on 2010-06-19T13:52:54.000+0000

Problem r22450 some constants not exists in windows generate notices.

<pre class="highlight">
protected $_validFacilities = array(
    LOG_AUTH,
    LOG_AUTHPRIV,
    LOG_CRON,
    LOG_DAEMON,
    LOG_KERN,
    LOG_LOCAL0,
    LOG_LOCAL1,
    LOG_LOCAL2,
    LOG_LOCAL3,
    LOG_LOCAL4,
    LOG_LOCAL5,
    LOG_LOCAL6,
    LOG_LOCAL7,
    LOG_LPR,
    LOG_MAIL,
    LOG_NEWS,
    LOG_SYSLOG,
    LOG_USER,
    LOG_UUCP,
);

Constants what may not exists depending do system operational: LOG_AUTHPRIV, LOG_CRON, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7, LOG_NEWS, LOG_SYSLOG, LOG_UUCP.

See define_syslog_variables section Return Values

Posted by Ramon Henrique Ornelas (ramon) on 2010-06-19T15:23:35.000+0000

Resolved problem notices in patch.

In patch added Zend_Log_Writer_Syslog::_initializeValidFacilities()

If Zend_Log_Writer_Syslog::_initializeValidFacilities() called in the Zend_Log_Writer_Syslog::__construct() could cause break BC.

Example:

<pre class="highlight">
class My_Custom_Writer_System extends Zend_Log_Writer_Syslog
{
    public function __construct($config)
    {
        // my code
    }
}

Posted by Matthew Weier O'Phinney (matthew) on 2010-06-21T05:16:32.000+0000

I made one minor change to the patch, and that was to do the detection of the validFacilities array size within the setFacility() method. This reduces the number of function calls necessary for applications where the facility may be changed multiple times.

Patch applied to trunk and 1.10 release branch.

Posted by Ramon Henrique Ornelas (ramon) on 2010-06-21T06:00:24.000+0000

Matthew

Amendment perfect

Thanks ;).

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts