ZF-7603: Syslog writer facility should be long

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:


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

Comments

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


openlog($this->_application, LOG_PID, constant($this->_facility));

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.

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

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

Unittests missing

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

Problem r22450 some constants not exists in windows generate notices.


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

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:


class My_Custom_Writer_System extends Zend_Log_Writer_Syslog
{
    public function __construct($config)
    {
        // my code
    }
}

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.

Matthew

Amendment perfect

Thanks ;).