From 1147e3622c68941f89c4d8923a54997f167c64d2 Mon Sep 17 00:00:00 2001 From: Franck Cassedanne Date: Thu, 2 Oct 2014 19:17:39 +0100 Subject: [PATCH 1/6] Work in progress --- src/Logger/AbstractLogger.php | 7 +-- tests/LoggerTest.php | 93 ++++++++--------------------------- 2 files changed, 25 insertions(+), 75 deletions(-) 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)); } } From 9c40ef1a25bcd00b7bee283718e2655852dd55ed Mon Sep 17 00:00:00 2001 From: Franck Cassedanne Date: Thu, 2 Oct 2014 19:19:03 +0100 Subject: [PATCH 2/6] i --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 931b64a..bc29fda 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,29 @@ Basic usage (*standalone*) Advanced usage (*multi-logs dispatcher*) -------------- +TODO: +```php + use Apix\Log; + + $logger = new Logger(); + + // the log bucket for critical, alert and emergency + $notify_log = new Log\Logger\Mail('foo@bar.boo'); + $notify_log->setMinLevel('critical'); + $logger->add($notify_log); + + // the log bucket for notice, warning and error + $prod_log = new Log\Logger\File('/tmp/apix_prod.log'); + $prod_log->setMinLevel('notice'); + $logger->add($prod_log); + + if (DEBUG) { + // the log bucket for info and debug + $dev_log = new Log\Logger\File('/tmp/apix_dev.log'); + $logger->add($dev_log); + } +``` + ```php use Apix\Log; From 9f781263660c15446a7d32400667ad7c2ea420cd Mon Sep 17 00:00:00 2001 From: Franck Cassedanne Date: Tue, 9 Jun 2015 18:41:15 +0100 Subject: [PATCH 3/6] Added a unit test bootstrap file. --- phpunit.xml.dist | 2 +- tests/bootstrap.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/bootstrap.php 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/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'; From 7eed8e524e979fad7c3ba6e722fe3fec16e55624 Mon Sep 17 00:00:00 2001 From: Franck Cassedanne Date: Tue, 9 Jun 2015 18:43:28 +0100 Subject: [PATCH 4/6] Added .gitattributes --- .gitattributes | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitattributes 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 From b8b9c973c98f0b6719e3a441dec3a24dcc2d3322 Mon Sep 17 00:00:00 2001 From: Franck Cassedanne Date: Tue, 9 Jun 2015 19:21:40 +0100 Subject: [PATCH 5/6] Improved the Advanced usage examples. --- README.md | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index bc29fda..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... @@ -26,44 +26,31 @@ Basic usage (*standalone*) Advanced usage (*multi-logs dispatcher*) -------------- -TODO: ```php use Apix\Log; - + $logger = new Logger(); - // the log bucket for critical, alert and emergency - $notify_log = new Log\Logger\Mail('foo@bar.boo'); - $notify_log->setMinLevel('critical'); - $logger->add($notify_log); + // 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('/tmp/apix_prod.log'); - $prod_log->setMinLevel('notice'); - $logger->add($prod_log); + // 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($urgent_log); + $this->logger->add($prod_log); if (DEBUG) { - // the log bucket for info and debug - $dev_log = new Log\Logger\File('/tmp/apix_dev.log'); + // 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); } -``` - -```php - use Apix\Log; - - $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 - - $this->logger->add($mail_log); - $this->logger->add($file_log); - // then notify the loggers... + // then (later) notify the loggers... $this->logger->notice('Some notice...'); $this->logger->critical('Blahh blahh...'); ``` From bfa9d5a68578f2bcd752eeeb67d3b90b7133dc10 Mon Sep 17 00:00:00 2001 From: Franck Cassedanne Date: Tue, 9 Jun 2015 19:23:16 +0100 Subject: [PATCH 6/6] Added a `CHANGELOG.md` file. --- CHANGELOG.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CHANGELOG.md 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. + + +
+  _|_|    _|_|    _|     _|      _|
+_|    _| _|    _|         _|    _|
+_|    _| _|    _| _|        _|_|
+_|_|_|_| _|_|_|   _| _|_|   _|_|
+_|    _| _|       _|      _|    _|
+_|    _| _|       _|     _|      _|
+