mirror of
https://github.com/Seldaek/monolog.git
synced 2025-02-24 06:52:34 +01:00
Fix a few details and add docs to the ChannelLevelActivationStrategy, refs #186
This commit is contained in:
parent
e9df30c7f5
commit
050bb52fd8
@ -16,6 +16,19 @@ namespace Monolog\Handler\FingersCrossed;
|
||||
* based on level per channel. e.g. trigger activation on level 'ERROR' by default, except
|
||||
* for records of the 'sql' channel; those should trigger activation on level 'WARN'.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* <code>
|
||||
* $activationStrategy = new ChannelLevelActivationStrategy(
|
||||
* Logger::CRITICAL,
|
||||
* array(
|
||||
* 'request' => Logger::ALERT,
|
||||
* 'sensitive' => Logger::ERROR,
|
||||
* )
|
||||
* );
|
||||
* $handler = new FingersCrossedHandler(new StreamHandler('php://stderr'), $activationStrategy);
|
||||
* </code>
|
||||
*
|
||||
* @author Mike Meessen <netmikey@gmail.com>
|
||||
*/
|
||||
class ChannelLevelActivationStrategy implements ActivationStrategyInterface
|
||||
@ -37,8 +50,8 @@ class ChannelLevelActivationStrategy implements ActivationStrategyInterface
|
||||
{
|
||||
if (isset($this->channelToActionLevel[$record['channel']])) {
|
||||
return $record['level'] >= $this->channelToActionLevel[$record['channel']];
|
||||
} else {
|
||||
}
|
||||
|
||||
return $record['level'] >= $this->defaultActionLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ use Monolog\Logger;
|
||||
* Only requests which actually trigger an error (or whatever your actionLevel is) will be
|
||||
* in the logs, but they will contain all records, not only those above the level threshold.
|
||||
*
|
||||
* You can find the various activation strategies in the
|
||||
* Monolog\Handler\FingersCrossed\ namespace.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class FingersCrossedHandler extends AbstractHandler
|
||||
@ -45,6 +48,8 @@ class FingersCrossedHandler extends AbstractHandler
|
||||
if (null === $activationStrategy) {
|
||||
$activationStrategy = new ErrorLevelActivationStrategy(Logger::WARNING);
|
||||
}
|
||||
|
||||
// convert simple int activationStrategy to an object
|
||||
if (!$activationStrategy instanceof ActivationStrategyInterface) {
|
||||
$activationStrategy = new ErrorLevelActivationStrategy($activationStrategy);
|
||||
}
|
||||
|
@ -138,8 +138,10 @@ class FingersCrossedHandlerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\FingersCrossedHandler::__construct
|
||||
* @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::__construct
|
||||
* @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::isHandlerActivated
|
||||
*/
|
||||
public function testActivationStrategy()
|
||||
public function testErrorLevelActivationStrategy()
|
||||
{
|
||||
$test = new TestHandler();
|
||||
$handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING));
|
||||
@ -151,9 +153,10 @@ class FingersCrossedHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\FingersCrossedHandler::__construct
|
||||
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::__construct
|
||||
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::isHandlerActivated
|
||||
*/
|
||||
public function testCategoryErrorLevelActivationStrategy()
|
||||
public function testChannelLevelActivationStrategy()
|
||||
{
|
||||
$test = new TestHandler();
|
||||
$handler = new FingersCrossedHandler($test, new ChannelLevelActivationStrategy(Logger::ERROR, array('othertest' => Logger::DEBUG)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user