Added Horde_Log_Filter_Suppress.
authorMike Naberezny <mike@naberezny.com>
Tue, 10 Feb 2009 04:54:19 +0000 (20:54 -0800)
committerMike Naberezny <mike@naberezny.com>
Tue, 10 Feb 2009 04:54:19 +0000 (20:54 -0800)
framework/Log/lib/Horde/Log/Filter/Suppress.php [new file with mode: 0644]
framework/Log/package.xml
framework/Log/test/Horde/Log/Filter/SuppressTest.php [new file with mode: 0644]

diff --git a/framework/Log/lib/Horde/Log/Filter/Suppress.php b/framework/Log/lib/Horde/Log/Filter/Suppress.php
new file mode 100644 (file)
index 0000000..ed430fd
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Horde Log package
+ *
+ * This package is based on Zend_Log from the Zend Framework
+ * (http://framework.zend.com).  Both that package and this
+ * one were written by Mike Naberezny and Chuck Hagenbuch.
+ *
+ * @category Horde
+ * @package  Horde_Log
+ * @subpackage Filters
+ * @author   Mike Naberezny <mike@maintainable.com>
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ */
+
+/**
+ * @category Horde
+ * @package  Horde_Log
+ * @subpackage Filters
+ * @author   Mike Naberezny <mike@maintainable.com>
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ */
+class Horde_Log_Filter_Suppress implements Horde_Log_Filter_Interface
+{
+    /**
+     * @var boolean
+     */
+    protected $_accept = true;
+
+    /**
+     * This is a simple boolean filter.
+     *
+     * Call suppress(true) to suppress all log events.
+     * Call suppress(false) to accept all log events.
+     *
+     * @param  boolean  $suppress  Should all log events be suppressed?
+     * @return  void
+     */
+    public function suppress($suppress)
+    {
+        $this->_accept = (! $suppress);
+    }
+
+    /**
+     * Returns TRUE to accept the message, FALSE to block it.
+     *
+     * @param  array    $event    event data
+     * @return boolean            accepted?
+     */
+    public function accept($event)
+    {
+        return $this->_accept;
+    }
+
+}
index e502fa2..153e123 100644 (file)
@@ -20,18 +20,18 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <email>mike@maintainable.com</email>
   <active>yes</active>
  </lead>
- <date>2007-10-21</date>
+ <date>2009-02-09</date>
  <time>23:26:00</time>
  <version>
-  <release>0.1.0</release>
-  <api>0.1.0</api>
+  <release>0.2.0</release>
+  <api>0.2.0</api>
  </version>
  <stability>
   <release>beta</release>
   <api>beta</api>
  </stability>
  <license uri="http://opensource.org/licenses/bsd-license.php">BSD</license>
- <notes>Initial Horde_Log release
+ <notes>* Added Horde_Log_Filter_Suppress.
  </notes>
  <contents>
   <dir name="/">
@@ -42,6 +42,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
        <file name="Interface.php" role="php" />
        <file name="Level.php" role="php" />
        <file name="Message.php" role="php" />
+       <file name="Suppress.php" role="php" />
       </dir> <!-- /lib/Horde/Log/Filter -->
       <dir name="Formatter">
        <file name="Interface.php" role="php" />
@@ -80,6 +81,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Log/Filter/Interface.php" as="Horde/Log/Filter/Interface.php" />
    <install name="lib/Horde/Log/Filter/Level.php" as="Horde/Log/Filter/Level.php" />
    <install name="lib/Horde/Log/Filter/Message.php" as="Horde/Log/Filter/Message.php" />
+   <install name="lib/Horde/Log/Filter/Suppress.php" as="Horde/Log/Filter/Suppress.php" />
    <install name="lib/Horde/Log/Formatter/Interface.php" as="Horde/Log/Formatter/Interface.php" />
    <install name="lib/Horde/Log/Formatter/Simple.php" as="Horde/Log/Formatter/Simple.php" />
    <install name="lib/Horde/Log/Formatter/Xml.php" as="Horde/Log/Formatter/Xml.php" />
diff --git a/framework/Log/test/Horde/Log/Filter/SuppressTest.php b/framework/Log/test/Horde/Log/Filter/SuppressTest.php
new file mode 100644 (file)
index 0000000..a6b4fb4
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Horde Log package
+ *
+ * This package is based on Zend_Log from the Zend Framework
+ * (http://framework.zend.com).  Both that package and this
+ * one were written by Mike Naberezny and Chuck Hagenbuch.
+ *
+ * @category Horde
+ * @package  Horde_Log
+ * @subpackage UnitTests
+ * @author   Mike Naberezny <mike@maintainable.com>
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ */   
+
+/**
+ * @category Horde
+ * @package  Horde_Log
+ * @subpackage UnitTests
+ * @author   Mike Naberezny <mike@maintainable.com>
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ */ 
+class Horde_Log_Filter_SuppressTest extends PHPUnit_Framework_TestCase 
+{
+    public function setUp()
+    {
+        $this->filter = new Horde_Log_Filter_Suppress();
+    }
+    
+    public function testSuppressIsInitiallyOff()
+    {
+        $this->assertTrue($this->filter->accept(array()));
+    }
+
+    public function testSuppressOn()
+    {
+        $this->filter->suppress(true);
+        $this->assertFalse($this->filter->accept(array()));
+        $this->assertFalse($this->filter->accept(array()));
+    }
+
+    public function testSuppressOff()
+    {
+        $this->filter->suppress(false);
+        $this->assertTrue($this->filter->accept(array()));
+        $this->assertTrue($this->filter->accept(array()));
+    }
+    
+    public function testSuppressCanBeReset()
+    {
+        $this->filter->suppress(true);
+        $this->assertFalse($this->filter->accept(array()));
+        $this->filter->suppress(false);
+        $this->assertTrue($this->filter->accept(array()));
+        $this->filter->suppress(true);
+        $this->assertFalse($this->filter->accept(array()));
+    }
+}