Просмотр исходного кода

Fix a few details and add docs to the ChannelLevelActivationStrategy, refs #186

Jordi Boggiano 12 лет назад
Родитель
Сommit
050bb52fd8

+ 15 - 2
src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php

@@ -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;
         }
+
+        return $record['level'] >= $this->defaultActionLevel;
     }
 }

+ 5 - 0
src/Monolog/Handler/FingersCrossedHandler.php

@@ -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);
         }

+ 6 - 3
tests/Monolog/Handler/FingersCrossedHandlerTest.php

@@ -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)));