ZF-8382: Zend_Log_Writer_Syslog does not utilize formatter


You can set an formatter for an Zend_Log_Writer_Syslog object. But as it seems this formatter is never used.

In my opinion the formatter should be utilized, once you are allowed to set one... See this very trivial patch to Zend/Log/Writer/Syslog.php:

--- Syslog.php (revision 19) +++ Syslog.php (working copy) @@ -170,6 +170,8 @@ $this->_initializeSyslog(); }

  • syslog($priority, $event['message']);
  • $line = $this->_formatter->format($event);
  • syslog($priority, $line); } }


Hi, I've run into this problem, too.

The above patch will fail with an error if a user tries to write to a syslog with no formatter.

There are two solutions:

(1) Detect if there's a formatter set & use it if there is [chrismsnz-zf-syslog-format-1.patch] - Inconsistent with how the other writer's formatters are initialised

(2) Set a default formatter (same approach as the other writers) [chrismsnz-zf-syslog-format-2.patch] - May need to override the default simple formatter string as it's probably not appropriate for syslog.

Approach #2 is probably preferred.

Cheers, Chris.

Added patches referenced in the above comment

Assigned to [~intiilapa]

The reason we didn't provide formatter support originally is because you're using the syslog facility -- syslog() is expecting both a priority and a message as arguments, and usually indicates the priority in the log itself. Using the Simple formatter, we'd end up seeing the priority duplicated in such logs.

As such, patch 1 makes more sense -- if no formatter is present, simply use the current approach (syslog($priority, $message)), and if and only if a formatter has been explicitly provided, use it.


Reopening in order to correct fix version.