1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 19:00:20 +02:00

Rename ThresholdHandler to OverflowHandler

This commit is contained in:
Kris Buist
2018-11-20 20:03:58 +01:00
parent bd79504f1e
commit 7dd453e694
3 changed files with 15 additions and 15 deletions

View File

@@ -125,10 +125,10 @@
has accessors to read out the information. has accessors to read out the information.
- [_HandlerWrapper_](../src/Monolog/Handler/HandlerWrapper.php): A simple handler wrapper you can inherit from to create - [_HandlerWrapper_](../src/Monolog/Handler/HandlerWrapper.php): A simple handler wrapper you can inherit from to create
your own wrappers easily. your own wrappers easily.
- [_ThresholdHandler_](../src/Monolog/Handler/ThresholdHandler.php): This handler will buffer all the log messages it - [_OverflowHandler_](../src/Monolog/Handler/OverflowHandler.php): This handler will buffer all the log messages it
receives, up until a configured threshold is reached, after it will pass all log messages to the wrapped handler. receives, up until a configured threshold of number of messages of a certain lever is reached, after it will pass all
Useful for applying in bath processing when you're only interested in significant failures instead of minor, single log messages to the wrapped handler. Useful for applying in bath processing when you're only interested in significant
erroneous events. failures instead of minor, single erroneous events.
## Formatters ## Formatters

View File

@@ -15,7 +15,7 @@ use Monolog\Logger;
/** /**
* Handler to only pass log messages when a certain threshold of messages is reached. * Handler to only pass log messages when a certain threshold of number of messages is reached.
* *
* This can be useful in cases of processing a batch of data, but you're for example only interested * This can be useful in cases of processing a batch of data, but you're for example only interested
* in case it fails catastrophically instead of a warning for 1 or 2 events. Worse things can happen, right? * in case it fails catastrophically instead of a warning for 1 or 2 events. Worse things can happen, right?
@@ -27,14 +27,14 @@ use Monolog\Logger;
* $handler = new SomeHandler(...) * $handler = new SomeHandler(...)
* *
* // Pass all warnings to the handler when more than 10 & all error messages when more then 5 * // Pass all warnings to the handler when more than 10 & all error messages when more then 5
* $threshold = new ThresholdHandler($handler, [Logger::WARNING => 10, Logger::ERROR => 5]); * $overflow = new OverflowHandler($handler, [Logger::WARNING => 10, Logger::ERROR => 5]);
* *
* $log->pushHandler($threshold); * $log->pushHandler($overflow);
*``` *```
* *
* @author Kris Buist <krisbuist@gmail.com> * @author Kris Buist <krisbuist@gmail.com>
*/ */
class ThresholdHandler extends AbstractHandler class OverflowHandler extends AbstractHandler
{ {
/** @var HandlerInterface */ /** @var HandlerInterface */
private $handler; private $handler;
@@ -105,7 +105,7 @@ class ThresholdHandler extends AbstractHandler
} }
if ($this->thresholdMap[$level] > 0) { if ($this->thresholdMap[$level] > 0) {
// The threshold is not yet reached, so we're buffering the record and lowering the threshold by 1 // The overflow threshold is not yet reached, so we're buffering the record and lowering the threshold by 1
$this->thresholdMap[$level]--; $this->thresholdMap[$level]--;
$this->buffer[$level][] = $record; $this->buffer[$level][] = $record;
return false === $this->bubble; return false === $this->bubble;

View File

@@ -16,14 +16,14 @@ use Monolog\Test\TestCase;
/** /**
* @author Kris Buist <krisbuist@gmail.com> * @author Kris Buist <krisbuist@gmail.com>
* @covers \Monolog\Handler\ThresholdHandler * @covers \Monolog\Handler\OverflowHandler
*/ */
class ThresholdHandlerTest extends TestCase class OverflowHandlerTest extends TestCase
{ {
public function testNotPassingRecordsBeneathLogLevel() public function testNotPassingRecordsBeneathLogLevel()
{ {
$testHandler = new TestHandler(); $testHandler = new TestHandler();
$handler = new ThresholdHandler($testHandler, [], Logger::INFO); $handler = new OverflowHandler($testHandler, [], Logger::INFO);
$handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG));
$this->assertFalse($testHandler->hasDebugRecords()); $this->assertFalse($testHandler->hasDebugRecords());
} }
@@ -31,7 +31,7 @@ class ThresholdHandlerTest extends TestCase
public function testPassThroughWithoutThreshold() public function testPassThroughWithoutThreshold()
{ {
$testHandler = new TestHandler(); $testHandler = new TestHandler();
$handler = new ThresholdHandler($testHandler, [], Logger::INFO); $handler = new OverflowHandler($testHandler, [], Logger::INFO);
$handler->handle($this->getRecord(Logger::INFO, 'Info 1')); $handler->handle($this->getRecord(Logger::INFO, 'Info 1'));
$handler->handle($this->getRecord(Logger::INFO, 'Info 2')); $handler->handle($this->getRecord(Logger::INFO, 'Info 2'));
@@ -48,7 +48,7 @@ class ThresholdHandlerTest extends TestCase
public function testHoldingMessagesBeneathThreshold() public function testHoldingMessagesBeneathThreshold()
{ {
$testHandler = new TestHandler(); $testHandler = new TestHandler();
$handler = new ThresholdHandler($testHandler, [Logger::INFO => 3]); $handler = new OverflowHandler($testHandler, [Logger::INFO => 3]);
$handler->handle($this->getRecord(Logger::DEBUG, 'debug 1')); $handler->handle($this->getRecord(Logger::DEBUG, 'debug 1'));
$handler->handle($this->getRecord(Logger::DEBUG, 'debug 2')); $handler->handle($this->getRecord(Logger::DEBUG, 'debug 2'));
@@ -74,7 +74,7 @@ class ThresholdHandlerTest extends TestCase
public function testCombinedThresholds() public function testCombinedThresholds()
{ {
$testHandler = new TestHandler(); $testHandler = new TestHandler();
$handler = new ThresholdHandler($testHandler, [Logger::INFO => 5, Logger::WARNING => 10]); $handler = new OverflowHandler($testHandler, [Logger::INFO => 5, Logger::WARNING => 10]);
$handler->handle($this->getRecord(Logger::DEBUG)); $handler->handle($this->getRecord(Logger::DEBUG));