/** * @param HandlerInterface $handler Handler. * @param string $deduplicationStore The file/path where the deduplication log should be kept * @param int $deduplicationLevel The minimum logging level for log records to be looked at for deduplication purposes * @param int $time The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not */ public function __construct(HandlerInterface $handler, $deduplicationStore = null, $deduplicationLevel = Logger::ERROR, $time = 60, $bubble = true) { parent::__construct($handler, 0, Logger::DEBUG, $bubble, false); $this->deduplicationStore = $deduplicationStore === null ? sys_get_temp_dir() . '/monolog-dedup-' . substr(md5(__FILE__), 0, 20) . '.log' : $deduplicationStore; $this->deduplicationLevel = Logger::toMonologLevel($deduplicationLevel); $this->time = $time; }
/** * {@inheritDoc} */ public function handle(array $record) { if (!$this->initialized) { DeferredUpdates::addCallableUpdate(array($this, 'close')); $this->initialized = true; } return parent::handle($record); }
public function testHandleBufferLimit() { $test = new TestHandler(); $handler = new BufferHandler($test, 2); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::INFO)); $handler->handle($this->getRecord(Logger::WARNING)); $handler->close(); $this->assertTrue($test->hasWarningRecords()); $this->assertTrue($test->hasInfoRecords()); $this->assertFalse($test->hasDebugRecords()); }
/** * @covers Monolog\Handler\BufferHandler::flush */ public function testFlush() { $test = new TestHandler(); $handler = new BufferHandler($test, 0); $handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::INFO)); $handler->flush(); $this->assertTrue($test->hasInfoRecords()); $this->assertTrue($test->hasDebugRecords()); $this->assertFalse($test->hasWarningRecords()); }
/** * @covers Monolog\Handler\BufferHandler::handle */ public function testHandleUsesProcessors() { $test = new TestHandler(); $handler = new BufferHandler($test); $handler->pushProcessor(function ($record) { $record['extra']['foo'] = true; return $record; }); $handler->handle($this->getRecord(Logger::WARNING)); $handler->flush(); $this->assertTrue($test->hasWarningRecords()); $records = $test->getRecords(); $this->assertTrue($records[0]['extra']['foo']); }
public function flushBuffer() { $this->bufferHandler->close(); }