|
@@ -15,6 +15,7 @@ use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
|
|
|
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
|
|
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
|
|
|
use Monolog\Logger;
|
|
use Monolog\Logger;
|
|
|
use Monolog\ResettableInterface;
|
|
use Monolog\ResettableInterface;
|
|
|
|
|
+use Monolog\Formatter\FormatterInterface;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Buffers all records until a certain level is reached
|
|
* Buffers all records until a certain level is reached
|
|
@@ -39,7 +40,7 @@ class FingersCrossedHandler extends AbstractHandler
|
|
|
protected $passthruLevel;
|
|
protected $passthruLevel;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @param callable|HandlerInterface $handler Handler or factory callable($record, $fingersCrossedHandler).
|
|
|
|
|
|
|
+ * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $fingersCrossedHandler).
|
|
|
* @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action
|
|
* @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action
|
|
|
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
|
|
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
|
|
|
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
|
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
|
@@ -88,15 +89,7 @@ class FingersCrossedHandler extends AbstractHandler
|
|
|
if ($this->stopBuffering) {
|
|
if ($this->stopBuffering) {
|
|
|
$this->buffering = false;
|
|
$this->buffering = false;
|
|
|
}
|
|
}
|
|
|
- if (!$this->handler instanceof HandlerInterface) {
|
|
|
|
|
- $record = end($this->buffer) ?: null;
|
|
|
|
|
-
|
|
|
|
|
- $this->handler = call_user_func($this->handler, $record, $this);
|
|
|
|
|
- if (!$this->handler instanceof HandlerInterface) {
|
|
|
|
|
- throw new \RuntimeException("The factory callable should return a HandlerInterface");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- $this->handler->handleBatch($this->buffer);
|
|
|
|
|
|
|
+ $this->getHandler(end($this->buffer) ?: null)->handleBatch($this->buffer);
|
|
|
$this->buffer = array();
|
|
$this->buffer = array();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -120,7 +113,7 @@ class FingersCrossedHandler extends AbstractHandler
|
|
|
$this->activate();
|
|
$this->activate();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- $this->handler->handle($record);
|
|
|
|
|
|
|
+ $this->getHandler($record)->handle($record);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return false === $this->bubble;
|
|
return false === $this->bubble;
|
|
@@ -140,8 +133,8 @@ class FingersCrossedHandler extends AbstractHandler
|
|
|
|
|
|
|
|
parent::reset();
|
|
parent::reset();
|
|
|
|
|
|
|
|
- if ($this->handler instanceof ResettableInterface) {
|
|
|
|
|
- $this->handler->reset();
|
|
|
|
|
|
|
+ if ($this->getHandler() instanceof ResettableInterface) {
|
|
|
|
|
+ $this->getHandler()->reset();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -167,11 +160,48 @@ class FingersCrossedHandler extends AbstractHandler
|
|
|
return $record['level'] >= $level;
|
|
return $record['level'] >= $level;
|
|
|
});
|
|
});
|
|
|
if (count($this->buffer) > 0) {
|
|
if (count($this->buffer) > 0) {
|
|
|
- $this->handler->handleBatch($this->buffer);
|
|
|
|
|
|
|
+ $this->getHandler(end($this->buffer) ?: null)->handleBatch($this->buffer);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->buffer = array();
|
|
$this->buffer = array();
|
|
|
$this->buffering = true;
|
|
$this->buffering = true;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Return the nested handler
|
|
|
|
|
+ *
|
|
|
|
|
+ * If the handler was provided as a factory callable, this will trigger the handler's instantiation.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return HandlerInterface
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getHandler(array $record = null)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->handler instanceof HandlerInterface) {
|
|
|
|
|
+ $this->handler = call_user_func($this->handler, $record, $this);
|
|
|
|
|
+ if (!$this->handler instanceof HandlerInterface) {
|
|
|
|
|
+ throw new \RuntimeException("The factory callable should return a HandlerInterface");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this->handler;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
|
+ */
|
|
|
|
|
+ public function setFormatter(FormatterInterface $formatter)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->getHandler()->setFormatter($formatter);
|
|
|
|
|
+
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getFormatter()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->getHandler()->getFormatter();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|