1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-23 01:26:11 +02:00

Merge pull request #769 from naderman/t/fingers-crossed-override-activation

Provide means to manually activate a FingersCrossedHandler
This commit is contained in:
Jordi Boggiano
2016-04-20 20:08:06 +01:00
2 changed files with 45 additions and 11 deletions

View File

@@ -79,6 +79,26 @@ class FingersCrossedHandler extends AbstractHandler
return true;
}
/**
* Manually activate this logger regardless of the activation strategy
*/
public function activate()
{
if ($this->stopBuffering) {
$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->buffer = array();
}
/**
* {@inheritdoc}
*/
@@ -96,17 +116,7 @@ class FingersCrossedHandler extends AbstractHandler
array_shift($this->buffer);
}
if ($this->activationStrategy->isHandlerActivated($record)) {
if ($this->stopBuffering) {
$this->buffering = false;
}
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");
}
}
$this->handler->handleBatch($this->buffer);
$this->buffer = array();
$this->activate();
}
} else {
$this->handler->handle($record);