Explorar o código

Provide means to manually activate a FingersCrossedHandler

This is useful if you have a FingersCrossedHandler set up and some where
in your application are interested in all output regardless of whether
the threshold is actually reached. For example to temporarily debug some
problem. One can replace the handler in that spot, but this is
signifcantly easier to use.
Nils Adermann %!s(int64=9) %!d(string=hai) anos
pai
achega
c677398c76
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      src/Monolog/Handler/FingersCrossedHandler.php

+ 10 - 1
src/Monolog/Handler/FingersCrossedHandler.php

@@ -36,6 +36,7 @@ class FingersCrossedHandler extends AbstractHandler
     protected $buffer = array();
     protected $stopBuffering;
     protected $passthruLevel;
+    protected $overrideActivated = false;
 
     /**
      * @param callable|HandlerInterface       $handler            Handler or factory callable($record, $fingersCrossedHandler).
@@ -79,6 +80,14 @@ class FingersCrossedHandler extends AbstractHandler
         return true;
     }
 
+    /**
+     * Manually activate this logger regardless of the activation strategy
+     */
+    public function activate()
+    {
+        $this->overrideActivated = true;
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -95,7 +104,7 @@ class FingersCrossedHandler extends AbstractHandler
             if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
                 array_shift($this->buffer);
             }
-            if ($this->activationStrategy->isHandlerActivated($record)) {
+            if ($this->overrideActivated || $this->activationStrategy->isHandlerActivated($record)) {
                 if ($this->stopBuffering) {
                     $this->buffering = false;
                 }