ZF-8382: Zend_Log_Writer_Syslog does not utilize formatter

Issue Type: Patch Created: 2009-11-24T05:51:44.000+0000 Last Updated: 2010-12-30T09:43:43.000+0000 Status: Closed Fix version(s): - 1.11.3 (01/Feb/11)

Reporter: Markus Warg (edgarwahn) Assignee: Benoît Durand (intiilapa) Tags: - Zend_Log

Related issues: Attachments: - chrismsnz-zf-syslog-format-1.patch


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


Posted by Chris Smith (chrismsnz) on 2010-02-08T14:45:46.000+0000

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.

Posted by Chris Smith (chrismsnz) on 2010-02-08T14:46:24.000+0000

Added patches referenced in the above comment

Posted by Ramon Henrique Ornelas (ramon) on 2010-10-20T19:31:14.000+0000

Assigned to [~intiilapa]

Posted by Matthew Weier O'Phinney (matthew) on 2010-12-17T11:39:32.000+0000

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.

Posted by Benoît Durand (intiilapa) on 2010-12-18T05:19:57.000+0000


Posted by Matthew Weier O'Phinney (matthew) on 2010-12-30T09:43:36.000+0000

Reopening in order to correct fix version.

Have you found an issue?

See the Overview section for more details.


© 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.