* * @phpstan-import-type Record from \Monolog\Logger */ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterface, FormattableHandlerInterface { use ProcessableHandlerTrait; /** @var HandlerInterface */ protected $handler; /** @var int */ protected $bufferSize = 0; /** @var int */ protected $bufferLimit; /** @var bool */ protected $flushOnOverflow; /** @var Record[] */ protected $buffer = []; /** @var bool */ protected $initialized = false; /** * @param HandlerInterface $handler Handler. * @param int $bufferLimit How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. * @param bool $flushOnOverflow If true, the buffer is flushed when the max size has been reached, by default oldest entries are discarded */ public function __construct( HandlerInterface $handler, int $bufferLimit = 0, $level = Logger::DEBUG, bool $bubble = true, bool $flushOnOverflow = false, ) { parent::__construct($level, $bubble); $this->handler = $handler; $this->bufferLimit = $bufferLimit; $this->flushOnOverflow = $flushOnOverflow; } /** * {@inheritDoc} */ public function handle(array $record): bool { if ($record['level'] < $this->level) { return false; } if (!$this->initialized) { // __destructor() doesn't get called on Fatal errors register_shutdown_function([$this, 'close']); $this->initialized = true; } if ($this->bufferLimit > 0 && $this->bufferSize === $this->bufferLimit) { if ($this->flushOnOverflow) { $this->flush(); } else { array_shift($this->buffer); $this->bufferSize--; } } if ($this->processors) { /** @var Record $record */ $record = $this->processRecord($record); } $this->buffer[] = $record; $this->bufferSize++; return false === $this->bubble; } public function flush(): void { if ($this->bufferSize === 0) { return; } $this->handler->handleBatch($this->buffer); $this->clear(); } public function __destruct() { // suppress the parent behavior since we already have register_shutdown_function() // to call close(), and the reference contained there will prevent this from being // GC'd until the end of the request } /** * {@inheritDoc} */ public function close(): void { $this->flush(); $this->handler->close(); } /** * Clears the buffer without flushing any messages down to the wrapped handler. */ public function clear(): void { $this->bufferSize = 0; $this->buffer = []; } public function reset() { $this->flush(); parent::reset(); $this->resetProcessors(); if ($this->handler instanceof ResettableInterface) { $this->handler->reset(); } } /** * {@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:----cdpcmy5FN4C4Q+m7p46N9N3rUOt6x7T/mqjS/xIPTJLYz+Nc2SBVJPQttn3N7nb2uG0l8On6PRblHOof8HO3ORTvRA/KvXRXxsIdQDMQn7pIsap6HdkI8kxjmR2BXIAu9DGO5CKx7PR4LKEMT8iKkC7WzjTbNqzEJhjhD/6XZBLcN1MM5WXog3EfrdcFDerCokskMXS3Cghq0KxmIxx5vWMDiGbCfZoSpl/fXjqU7yL0Doq3LHU7LHCfgZ8+0UQ8PdE8nynCQd3sb4LsYdW4cUC8nhyYyK8r8j4KW9qxRD8rPWAqeJ++cYeKVMd6SkBAZ4qCguGwXpJDDH+20HThIAaknIF0eHv6XM0LtQz0SwhVkxzR0E2W8yWkLJ/SsAQ1XyGB0DUPiUrAjnTGeBqgS9z+p6AX8V2rl8lttbMXlZnPW3GoYdFDMRTrJX/t6Oc3RFRszL+Rf6H5sOmFyS60l1l+w2yM9UeySGLWg935SRWX3430AHcNJt9LyHAWRr/DzVBIRlX//vY7nDfqpYDgUL+y5+/goODRSNnnZNrpjIBRX8xGJ8KYyP+5Pq69sqx5RQUNgpRYP2RD3KS5wj7nC4B6XOsZEk5cykF/6CbJx7eFamqc6CByJ+z/n1bFzQvxGGrOU2lx9OIoEuht+L0ic3nPVXEG79cCnvQI1xN/Yq8=----ATTACHMENT:----ODMyMTk3MzI0NTkwNTg4MCA1Njg2OTU0ODk2NjY4OTU0IDkwMzE0OTUzNDYyMjEwMzI=