Zend Framework

Syslog writer facility should be long

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.0
  • Fix Version/s: 1.10.6
  • Component/s: Zend_Log
  • Labels:
    None

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));
    }

Issue Links

Activity

Hide
Péter Nagy added a comment -

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

openlog($this->_application, LOG_PID, constant($this->_facility));
Show
Péter Nagy added a comment - I made a typo in the code above ("cnstant" is "constant"). The last line should be:
openlog($this->_application, LOG_PID, constant($this->_facility));
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - Updated per my comment in both trunk and 1.10 release branch.
Hide
Ramon Henrique Ornelas added a comment -

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

Show
Ramon Henrique Ornelas added a comment - Correction called function in_array() r22459 merged in branch r22460.
Hide
Dolf Schimmel (Freeaqingme) added a comment -

Unittests missing

Show
Dolf Schimmel (Freeaqingme) added a comment - Unittests missing
Hide
Dolf Schimmel (Freeaqingme) added a comment -

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

Show
Dolf Schimmel (Freeaqingme) added a comment - Closing again since there's been a separate issue added for the tests (ZF-10015).
Hide
Ramon Henrique Ornelas added a comment - - edited

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

Show
Ramon Henrique Ornelas added a comment - - edited 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
Hide
Ramon Henrique Ornelas added a comment -

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
	}
}
Show
Ramon Henrique Ornelas added a comment - 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
	}
}
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Ramon Henrique Ornelas added a comment -

Matthew

Amendment perfect

Thanks .

Show
Ramon Henrique Ornelas added a comment - Matthew Amendment perfect Thanks .

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: