diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..967b6c7
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,9 @@
+/.gitattributes export-ignore
+/.gitignore export-ignore
+/.travis.yml export-ignore
+/.scrutinizer.yml export-ignore
+/CHANGELOG.md export-ignore
+/CONTRIBUTING.md export-ignore
+/README.md export-ignore
+/phpunit.xml.dist export-ignore
+/tests export-ignore
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..0b3b316
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,24 @@
+# APIx-log changelog
+
+#### Version 1.0.1 (9-Jun-2015)
+- Added Scrutinizer checks.
+- Added `.gitattributes` file.
+- Added a unit tests `bootstrap.php` file.
+- Added a default timezone to the unit tests bootstraper.
+- Fixed the context array handler (convert data to JSON).
+- Added additional tests and minor changes.
+- Updated the examples in `README.md`.
+- Added a `CHANGELOG.md` file.
+
+#### Version 1.0.0 (30-Sept-2014)
+- Initial release.
+
+
+
+ _|_| _|_| _| _| _|
+_| _| _| _| _| _|
+_| _| _| _| _| _|_|
+_|_|_|_| _|_|_| _| _|_| _|_|
+_| _| _| _| _| _|
+_| _| _| _| _| _|
+
diff --git a/README.md b/README.md
index 931b64a..7e3780d 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Basic usage (*standalone*)
```php
use Apix\Log;
- $logger = new Logger\File('/tmp/alerts.log');
+ $logger = new Logger\File('/var/log/apix.log');
$logger->setMinLevel('alert'); // same as Psr\Log\LogLevel::ALERT
// then later, just push/send an alert...
@@ -31,16 +31,26 @@ Advanced usage (*multi-logs dispatcher*)
$logger = new Logger();
- $file_log = new Logger\File('/tmp/debug.log');
- $file_log->setMinLevel('debug'); // same as Psr\Log\LogLevel::DEBUG
-
- $mail_log = new Logger\Mail('foo@bar.tld');
- $mail_log->setMinLevel('critical'); // or Psr\Log\LogLevel::CRITICAL
+ // The log bucket for critical, alert and emergency.
+ $urgent_log = new Logger\Mail('foo@bar.boo');
+ $urgent_log->setMinLevel('critical'); // same Psr\Log\LogLevel::CRITICAL
+
+ // The log bucket for notice, warning and error.
+ $prod_log = new Log\Logger\File('/var/log/apix_prod.log');
+ $prod_log->setMinLevel('notice'); // same Psr\Log\LogLevel::NOTICE
- $this->logger->add($mail_log);
- $this->logger->add($file_log);
+ $this->logger->add($urgent_log);
+ $this->logger->add($prod_log);
+
+ if (DEBUG) {
+ // The develop log bucket for info and debug
+ $dev_log = new Log\Logger\File('/tmp/apix_develop.log');
+ $dev_log->setMinLevel('debug'); // same as Psr\Log\LogLevel::DEBUG
+
+ $logger->add($dev_log);
+ }
- // then notify the loggers...
+ // then (later) notify the loggers...
$this->logger->notice('Some notice...');
$this->logger->critical('Blahh blahh...');
```
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 6bb37db..4c12068 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -10,7 +10,7 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
- bootstrap="vendor/autoload.php"
+ bootstrap="tests/bootstrap.php"
>
diff --git a/src/Logger/AbstractLogger.php b/src/Logger/AbstractLogger.php
index 604fd3d..2d7f18a 100644
--- a/src/Logger/AbstractLogger.php
+++ b/src/Logger/AbstractLogger.php
@@ -44,7 +44,7 @@ abstract class AbstractLogger extends AbsPsrLogger
protected $min_level = 0;
/**
- * Whether this logger allows log to cascade downstream.
+ * Whether this logger will cascade downstream.
* @var bool
*/
protected $cascading = true;
@@ -116,14 +116,15 @@ public function isHandling($level_code)
}
/**
- * Sets the minimal level at which this handler will be triggered.
+ * Sets the minimal level at which this logger will be triggered.
*
* @param string $name
* @return self
*/
- public function setMinLevel($name)
+ public function setMinLevel($name, $cascading=true)
{
$this->min_level = (int) static::getLevelCode($name);
+ $this->cascading = (boolean) $cascading;
return $this;
}
diff --git a/tests/LoggerTest.php b/tests/LoggerTest.php
index 54b49ae..6ee37f3 100644
--- a/tests/LoggerTest.php
+++ b/tests/LoggerTest.php
@@ -121,28 +121,7 @@ public function testLogWillNotProcess()
$this->logger->warning('test');
}
-// todo
- public function _testExample()
- {
- $g = $this->_getMocklogger( array('process') );
- $g->expects($this->once())->method('process');
-
- $a = $this->_getMocklogger( array('process') );
- $a->setMinLevel( LogLevel::ALERT );
- $a->expects($this->once())->method('process');
-
- $this->logger->add($g);
- $this->logger->add($a);
-
- $this->logger->alert('test');
- $this->logger->debug('test');
-
- }
-
- /**
- * @group test
- */
- public function testFunctional()
+ public function TODO_testFunctional()
{
// $this->expectOutputString('foo');
@@ -162,64 +141,34 @@ public function testFunctional()
$this->logger->debug('test filed logged');
$this->logger->alert('test by email {bb}', array('bb'=>123));
-
}
- public function _testHandlersNotCalledBeforeFirstHandling()
+ /**
+ * @group todo
+ */
+ public function testFunctionalExample()
{
- $l1 = $this->_getMocklogger();
- $l1->expects($this->never())
- ->method('isHandling')
- ->will($this->returnValue(false));
-
- $l1->expects($this->once())
- ->method('process')
- ->will($this->returnValue(false));
+ $logger = new Logger();
- $this->logger->add($l1);
-
- $l2 = $this->_getMocklogger();
- $l2->expects($this->once())
- ->method('isHandling')
- ->will($this->returnValue(true));
+ // the log bucket for critical, alert and emergency
+ $mail_log = new Logger\Mail('foo@bar.boo');
+ $mail_log->setMinLevel('critical');
+ $this->logger->add($mail_log);
- $l2->expects($this->once())
- ->method('process')
- ->will($this->returnValue(false));
+ // the log bucket for notice, warning and error
+ $prod_log = new Logger\File('/tmp/apix_prod.log');
+ $prod_log->setMinLevel('notice');
+ $this->logger->add($prod_log);
- $this->logger->add($l2);
+ if (true) {
+ // the log bucket for info and debug
+ $dev_log = new Logger\File('/tmp/apix_dev.log');
+ $this->logger->add($dev_log);
+ }
- $l3 = $this->_getMocklogger();
- $l3->expects($this->once())
- ->method('isHandling')
- ->will($this->returnValue(false))
- ;
- $l3->expects($this->never())
- ->method('process')
- ;
- $this->logger->add($l3);
-
- $this->logger->debug('test');
- }
-
- public function _testGetFirstLoggerIndex()
- {
- $l1 = $this->_getMocklogger();
- $l1->expects($this->any())
- ->method('isHandling')
- ->will($this->returnValue(false));
- $this->logger->add($l1);
-
- $this->assertFalse($this->logger->getFirstLoggerIndex(LogLevel::DEBUG));
-
- $l2 = $this->_getMocklogger();
- $l2->setMinLevel( LogLevel::ALERT );
- $l2->expects($this->any())
- ->method('isHandling')
- ->will($this->returnValue(true));
- $this->logger->add($l2);
+ $this->logger->debug('test filed logged');
+ $this->logger->alert('test by email {bb}', array('bb'=>123));
- $this->assertSame(0, $this->logger->getFirstLoggerIndex(LogLevel::DEBUG));
}
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..6bbc1c5
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,21 @@
+
+ *
+ * @license http://opensource.org/licenses/BSD-3-Clause New BSD License
+ *
+ */
+
+namespace Apix;
+
+// Set the default timezone
+date_default_timezone_set('UTC');
+
+define('APP_VENDOR', realpath(__DIR__ . '/../vendor'));
+
+// Composer
+$loader = require APP_VENDOR . '/autoload.php';