-- Thomas Gelf <[EMAIL PROTECTED]> wrote
(on Friday, 19 September 2008, 07:41 PM +0200):
> Here what Zend_Log_Writer_Syslog could look like:
Could you write a proposal for this, please? This is definitely a useful
addition.
> class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
> {
> /**
> * Maps Zend_Log priorities to PHP's syslog priorities
> * @var array
> */
> protected $_priorities = array(Zend_Log::EMERG => LOG_EMERG,
> Zend_Log::ALERT => LOG_ALERT,
> Zend_Log::CRIT => LOG_CRIT,
> Zend_Log::ERR => LOG_ERR,
> Zend_Log::WARN => LOG_WARNING,
> Zend_Log::NOTICE => LOG_NOTICE,
> Zend_Log::INFO => LOG_INFO,
> Zend_Log::DEBUG => LOG_DEBUG);
>
> /**
> * The default log priority - for unmapped custom priorities
> * @var string
> */
> protected $_defaultPriority = LOG_NOTICE;
>
> public function __construct($application = 'Zend_Log')
> {
> if (false === @openlog($application, LOG_PID, LOG_USER)) {
> throw new Zend_Log_Exception('Cannot connect to syslog');
> }
> }
>
> /**
> * Close syslog.
> *
> * @return void
> */
> public function shutdown()
> {
> @closelog();
> }
>
> /**
> * Write a message to syslog.
> *
> * @param array $event event data
> * @return void
> */
> protected function _write($event)
> {
> if (array_key_exists($event['priority'], $this-> _priorities)) {
> $priority = $this-> _priorityStyles[$event['priority']];
> } else {
> $priority = $this-> _defaultPriority;
> }
>
> if (false === @syslog($priority, $event['message'])) {
> throw new Zend_Log_Exception('Unable to write to syslog');
> }
> }
> }
>
> Even if LOG_USER should be fine for most users (it is available on
> Windows too) methods allowing to change facility could be added, the
> rest should be fine.
>
> Could someone test if this would "work out of the box" on windows?
>
> Cheers,
> Thomas
>
> NB: I'm not sure about the @'s in front of the syslog functions - as
> syslog is working fine on all of my systems I never experienced
> such an error ;-) If no one knows I'll test it - if there is even
> one single scenario producing a PHP-notice they have to stay there.
>
>
> Thomas Gelf schrieb:
> > Hi list,
> >
> > as surely most of you have a lot of free time available I'll throw
> > in a new old topic to hopefully be discussed in this round ;-)
> >
> > It's about logging. I like Zend_Log, it's well done - but the writers
> > currently available are not an option for most of my projects. Let's
> > make some example:
> >
> > * stream writers writing to local files are running fine, are not
> > blocking parallel requests and should be ok so far if you just
> > want your logs to be written down somewhere
> >
> > * it's difficult to set up a secure environment allowing PHP scripts
> > running under different UIDs writing to the same log file (mostly
> > leading to insecure logfile permissions or strange hacks)
> >
> > * hacked PHP sites are able to modify (application) log entries if
> > PHP is able to write to them
> >
> > * if you want a cronjob to rotate log files for a PHP-written daemon
> > you have to implement signal handlers (who has ever done so knows
> > that this could be a really funny task)
> >
> > * writing to DB is great for small projects - but impossible for sites
> > with heavy traffic. If you want to handle high loads your application
> > should be able to serve most requests without the need to connect to
> > your database cluster
> >
> > * ZF documentation should make people aware of locking and therefore
> > performance issues when using MyISAM instead of InnoDB on MySQL
> >
> > * who wants to achieve a distributed centralized logging is currently
> > either forced to write it's own syslog writer or probably going to
> > reimplement things syslog would usually do for you
> >
> > Said all this: why is there still no Zend_Log_Writer_Syslog? Windows
> > is no excuse - PHP's syslog() function exists also there, so we should
> > be able to satisfy ZF's rules. And those rare windows people taking
> > care of their logs will surely be able to find out where they are going
> > to finish ;-) We should however avoid LOCAL*-facilities, as far as I
> > know (didn't test it) they are not available on windows.
> >
> > Thanks for your feedback - and have a nice weekend!
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/