Permalink
Browse files

[#2271] Incorporate feedbac

- Incorporated feedback from comments
- Added @see annotation pointing to python Logbook documentation
- Added writer to WriterPluginManager
  • Loading branch information...
1 parent 6a6c7c4 commit 576b759823906b7c8b63860d43192ffe92df0bfb @weierophinney weierophinney committed Sep 18, 2012
Showing with 32 additions and 28 deletions.
  1. +23 −20 library/Zend/Log/Writer/FingersCrossed.php
  2. +9 −8 library/Zend/Log/WriterPluginManager.php
@@ -20,8 +20,9 @@
/**
* Buffers all events until the strategy determines to flush them.
*
- * @category Zend
- * @package Zend_Log
+ * @see http://packages.python.org/Logbook/api/handlers.html#logbook.FingersCrossedHandler
+ * @category Zend
+ * @package Zend_Log
* @subpackage Writer
*/
class FingersCrossed extends AbstractWriter
@@ -68,13 +69,12 @@ public function __construct(WriterInterface $writer, $filterOrPriority = null, $
$this->writer = $writer;
if (null === $filterOrPriority) {
- $this->addFilter(new PriorityFilter(Logger::WARN));
+ $filterOrPriority = new PriorityFilter(Logger::WARN);
} elseif (!$filterOrPriority instanceof FilterInterface) {
- $this->addFilter(new PriorityFilter($filterOrPriority));
- } else {
- $this->addFilter($filterOrPriority);
+ $filterOrPriority = new PriorityFilter($filterOrPriority);
}
+ $this->addFilter($filterOrPriority);
$this->bufferSize = $bufferSize;
}
@@ -113,22 +113,25 @@ protected function isActivated(array $event)
*/
protected function doWrite(array $event)
{
- if ($this->buffering) {
- $this->buffer[] = $event;
+ if (!$this->buffering) {
+ $this->writer->write($event);
+ return;
+ }
+
+ $this->buffer[] = $event;
- if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
- array_shift($this->buffer);
- }
+ if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
+ array_shift($this->buffer);
+ }
- if ($this->isActivated($event)) {
- $this->buffering = false;
+ if (!$this->isActivated($event)) {
+ return;
+ }
+
+ $this->buffering = false;
- foreach ($this->buffer as $bufferedEvent) {
- $this->writer->write($bufferedEvent);
- }
- }
- } else {
- $this->writer->write($event);
+ foreach ($this->buffer as $bufferedEvent) {
+ $this->writer->write($bufferedEvent);
}
}
@@ -162,4 +165,4 @@ public function shutdown()
$this->writer->shutdown();
$this->buffer = null;
}
-}
+}
@@ -24,14 +24,15 @@ class WriterPluginManager extends AbstractPluginManager
* @var array
*/
protected $invokableClasses = array(
- 'db' => 'Zend\Log\Writer\Db',
- 'firephp' => 'Zend\Log\Writer\FirePhp',
- 'mail' => 'Zend\Log\Writer\Mail',
- 'mock' => 'Zend\Log\Writer\Mock',
- 'null' => 'Zend\Log\Writer\Null',
- 'stream' => 'Zend\Log\Writer\Stream',
- 'syslog' => 'Zend\Log\Writer\Syslog',
- 'zendmonitor' => 'Zend\Log\Writer\ZendMonitor',
+ 'db' => 'Zend\Log\Writer\Db',
+ 'fingerscrossed' => 'Zend\Log\Writer\FingersCrossed',
+ 'firephp' => 'Zend\Log\Writer\FirePhp',
+ 'mail' => 'Zend\Log\Writer\Mail',
+ 'mock' => 'Zend\Log\Writer\Mock',
+ 'null' => 'Zend\Log\Writer\Null',
+ 'stream' => 'Zend\Log\Writer\Stream',
+ 'syslog' => 'Zend\Log\Writer\Syslog',
+ 'zendmonitor' => 'Zend\Log\Writer\ZendMonitor',
);
/**

0 comments on commit 576b759

Please sign in to comment.