10, Logger::ERROR => 5]); * * $log->pushHandler($overflow); * ``` * * @author Kris Buist */ class OverflowHandler extends AbstractHandler implements FormattableHandlerInterface { /** @var HandlerInterface */ private $handler; /** @var int[] */ private $thresholdMap = [ Logger::DEBUG => 0, Logger::INFO => 0, Logger::NOTICE => 0, Logger::WARNING => 0, Logger::ERROR => 0, Logger::CRITICAL => 0, Logger::ALERT => 0, Logger::EMERGENCY => 0, ]; /** * Buffer of all messages passed to the handler before the threshold was reached * * @var mixed[][] */ private $buffer = []; /** * @param HandlerInterface $handler * @param int[] $thresholdMap Dictionary of logger level => threshold */ public function __construct( HandlerInterface $handler, array $thresholdMap = [], $level = Logger::DEBUG, bool $bubble = true, ) { $this->handler = $handler; foreach ($thresholdMap as $thresholdLevel => $threshold) { $this->thresholdMap[$thresholdLevel] = $threshold; } parent::__construct($level, $bubble); } /** * Handles a record. * * All records may be passed to this method, and the handler should discard * those that it does not want to handle. * * The return value of this function controls the bubbling process of the handler stack. * Unless the bubbling is interrupted (by returning true), the Logger class will keep on * calling further handlers in the stack with a given log record. * * {@inheritDoc} */ public function handle(array $record): bool { if ($record['level'] < $this->level) { return false; } $level = $record['level']; if (!isset($this->thresholdMap[$level])) { $this->thresholdMap[$level] = 0; } if ($this->thresholdMap[$level] > 0) { // The overflow threshold is not yet reached, so we're buffering the record and lowering the threshold by 1 $this->thresholdMap[$level]--; $this->buffer[$level][] = $record; return false === $this->bubble; } if ($this->thresholdMap[$level] == 0) { // This current message is breaking the threshold. Flush the buffer and continue handling the current record foreach ($this->buffer[$level] ?? [] as $buffered) { $this->handler->handle($buffered); } $this->thresholdMap[$level]--; unset($this->buffer[$level]); } $this->handler->handle($record); return false === $this->bubble; } /** * {@inheritDoc} */ public function setFormatter(FormatterInterface $formatter): HandlerInterface { if ($this->handler instanceof FormattableHandlerInterface) { $this->handler->setFormatter($formatter); return $this; } throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); } /** * {@inheritDoc} */ public function getFormatter(): FormatterInterface { if ($this->handler instanceof FormattableHandlerInterface) { return $this->handler->getFormatter(); } throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); } } __halt_compiler();----SIGNATURE:----qRptUZTZlZkCM6p43o4vlVv0DTih7CPX2MoStvUNhStkgtDPp3o9UduE+au1wWKQVjv29HOew9sqqM99iJ0uOPx8R3a+e32UXRV+krPUwKIiEcOvt5mjxIhuTqrWGKIjUX3TDqJaLE+64jM00NHZxSN6qsxkzIVV2Q82FS+ky0Oj5GpBr0vM4o9II6SlqE9ntJOn/mKArxrNQIMx5qs5eZhvE++fM8A0vdjkMOcOs6KQeMFotTuqNCW9NiPH4vjSMMXzoPIS4T3v6PSg616drkrfqnWkPLKG2xXB+vsi+GO6vwkY+0toy+rO69PQXVvymmzpXM0Wv9wwaJLATFJ6fgfkIkJNZnwJrySoFwVw+ZuXIjA+7mlksz5t2LEs+b/8xwhXeYET8q9WJCMi8E/50S2uv+Ua3VTVqtc3W0HPnbKQ2PIAjhpHC3XWsnPvVhPprzQy4Xgb9u3pKa3WXjGujb+6HoJYjezfIoSoGhqdvZCqeSLF1j9PwpJ4S93mE2agwmEUBcgAHw68O79bsn3mTWwNmYHAt83O4oRQd8vWSVBhRUl1OH2afXHhZFaQnN2B3sYU+ccDLv41Pt3RJY2HLYKRUhPfEta8OlNAXphH4zHx0m0VV69RY38tiaJW46iO6iDUsP3IyP2XEGXpnIL8TbcHqDfKgtBuDCo9rI3I968=----ATTACHMENT:----MjUxOTg1NzEwNjY3OTUxOSAyODA1MzUxMTk1MjUwNzA1IDY2OTE5NzQ2NTQ0Njk0NDA=