|
@@ -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
|
|
@@ -32,7 +33,7 @@ use Monolog\ResettableInterface;
|
|
|
*
|
|
*
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
*/
|
|
*/
|
|
|
-class FingersCrossedHandler extends Handler implements ProcessableHandlerInterface, ResettableInterface
|
|
|
|
|
|
|
+class FingersCrossedHandler extends Handler implements ProcessableHandlerInterface, ResettableInterface, FormattableHandlerInterface
|
|
|
{
|
|
{
|
|
|
use ProcessableHandlerTrait;
|
|
use ProcessableHandlerTrait;
|
|
|
|
|
|
|
@@ -46,7 +47,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
|
|
|
protected $bubble;
|
|
protected $bubble;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @param callable|HandlerInterface $handler Handler or factory callable($record, $fingersCrossedHandler).
|
|
|
|
|
|
|
+ * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $fingersCrossedHandler).
|
|
|
* @param int|string|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action, or a level name/value at which the handler is activated
|
|
* @param int|string|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action, or a level name/value at which the handler is activated
|
|
|
* @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
|
|
@@ -95,15 +96,8 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
|
|
|
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 = [];
|
|
$this->buffer = [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -125,7 +119,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
|
|
|
$this->activate();
|
|
$this->activate();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- $this->handler->handle($record);
|
|
|
|
|
|
|
+ $this->getHandler($record)->handle($record);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return false === $this->bubble;
|
|
return false === $this->bubble;
|
|
@@ -147,8 +141,8 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
|
|
|
|
|
|
|
|
$this->resetProcessors();
|
|
$this->resetProcessors();
|
|
|
|
|
|
|
|
- if ($this->handler instanceof ResettableInterface) {
|
|
|
|
|
- $this->handler->reset();
|
|
|
|
|
|
|
+ if ($this->getHandler() instanceof ResettableInterface) {
|
|
|
|
|
+ $this->getHandler()->reset();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -174,11 +168,48 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
|
|
|
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 = [];
|
|
$this->buffer = [];
|
|
|
$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): HandlerInterface
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->getHandler()->setFormatter($formatter);
|
|
|
|
|
+
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getFormatter(): FormatterInterface
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->getHandler()->getFormatter();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|