Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
frqnck committed Jun 9, 2015
2 parents faa1533 + bfa9d5a commit 0a1943d
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 85 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.


<pre>
_|_| _|_| _| _| _|
_| _| _| _| _| _|
_| _| _| _| _| _|_|
_|_|_|_| _|_|_| _| _|_| _|_|
_| _| _| _| _| _|
_| _| _| _| _| _|
</pre>
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -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('[email protected]');
$mail_log->setMinLevel('critical'); // or Psr\Log\LogLevel::CRITICAL
// The log bucket for critical, alert and emergency.
$urgent_log = new Logger\Mail('[email protected]');
$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...');
```
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Apix Log Unit Tests">
Expand Down
7 changes: 4 additions & 3 deletions src/Logger/AbstractLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
93 changes: 21 additions & 72 deletions tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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('[email protected]');
$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));
}

}
21 changes: 21 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
*
* This file is part of the Apix Project.
*
* (c) Franck Cassedanne <franck at ouarz.net>
*
* @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';

0 comments on commit 0a1943d

Please sign in to comment.