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

Merge branch '1.x', clean up close/reset for 2.0, refs #997

This commit is contained in:
Jordi Boggiano
2018-11-04 22:41:52 +01:00
13 changed files with 125 additions and 30 deletions

View File

@@ -131,25 +131,16 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
*/
public function close(): void
{
if (null !== $this->passthruLevel) {
$level = $this->passthruLevel;
$this->buffer = array_filter($this->buffer, function ($record) use ($level) {
return $record['level'] >= $level;
});
if (count($this->buffer) > 0) {
$this->handler->handleBatch($this->buffer);
$this->buffer = [];
}
}
$this->flushBuffer();
$this->handler->close();
}
/**
* Resets the state of the handler. Stops forwarding records to the wrapped handler.
*/
public function reset()
{
$this->buffer = array();
$this->buffering = true;
$this->flushBuffer();
$this->resetProcessors();
if ($this->handler instanceof ResettableInterface) {
$this->handler->reset();
@@ -166,4 +157,23 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
$this->buffer = [];
$this->reset();
}
/**
* Resets the state of the handler. Stops forwarding records to the wrapped handler.
*/
private function flushBuffer()
{
if (null !== $this->passthruLevel) {
$level = $this->passthruLevel;
$this->buffer = array_filter($this->buffer, function ($record) use ($level) {
return $record['level'] >= $level;
});
if (count($this->buffer) > 0) {
$this->handler->handleBatch($this->buffer);
}
}
$this->buffer = [];
$this->buffering = true;
}
}