-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change default logging to disabled, custom options
Previously, the default logging state was all Errors, logged to file. This has been changed so that logging is disabled by default (using Analog's Null handler). In addition, the Analog handler has been exposed through the settings, so that a user may specify a custom handler (syslog, etc) instead of the default file handler. Closes #12
- Loading branch information
1 parent
12cb2f2
commit 474fa95
Showing
2 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* User: Zachary Tong | ||
* Date: 3/10/13 | ||
* Time: 10:36 AM | ||
*/ | ||
|
||
namespace Sherlock\tests; | ||
use Analog\Analog; | ||
use Sherlock\Sherlock; | ||
|
||
class SherlockSettingsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Sherlock | ||
*/ | ||
protected $object; | ||
|
||
/** | ||
* Sets up the fixture, for example, opens a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Tears down the fixture, for example, closes a network connection. | ||
* This method is called after a test is executed. | ||
*/ | ||
protected function tearDown() | ||
{ | ||
|
||
} | ||
|
||
function assertThrowsException($exception_name, $code) { | ||
$e = null; | ||
try{ | ||
$code(); | ||
}catch (\Exception $e) { | ||
// No more code, we only want to catch the exception in $e | ||
} | ||
|
||
$this->assertInstanceOf($exception_name, $e); | ||
} | ||
|
||
|
||
public function testSettings() | ||
{ | ||
$sherlock = new Sherlock(); | ||
$data = $sherlock->getSherlockSettings(); | ||
|
||
//Check default Null handler | ||
$settings = array(); | ||
$settings['log.enabled'] = false; | ||
$sherlock = new Sherlock($settings); | ||
$data = $sherlock->getSherlockSettings(); | ||
$this->assertEquals($settings['log.enabled'], $data['log.enabled']); | ||
|
||
$nullHandler = \Analog\Handler\Null::init(); | ||
$this->assertEquals($nullHandler, $data['log.handler']); | ||
|
||
|
||
//Check default File handler | ||
$settings = array(); | ||
$settings['log.enabled'] = true; | ||
$sherlock = new Sherlock($settings); | ||
$data = $sherlock->getSherlockSettings(); | ||
$this->assertEquals($settings['log.enabled'], $data['log.enabled']); | ||
|
||
$fileHandler = \Analog\Handler\Threshold::init (\Analog\Handler\File::init ($data['base'] .$data['log.file']), Analog::ERROR); | ||
$this->assertEquals($fileHandler, $data['log.handler']); | ||
|
||
|
||
//Check default File handler with custom path | ||
$settings = array(); | ||
$settings['log.enabled'] = true; | ||
$settings['log.file'] = '../sherlock.log'; | ||
$sherlock = new Sherlock($settings); | ||
$data = $sherlock->getSherlockSettings(); | ||
$this->assertEquals($settings['log.file'], $data['log.file']); | ||
|
||
$fileHandler = \Analog\Handler\Threshold::init (\Analog\Handler\File::init ($data['base'] .$data['log.file']), Analog::ERROR); | ||
$this->assertEquals($fileHandler, $data['log.handler']); | ||
|
||
|
||
//Check custom handler (syslog) | ||
$syslogHandler = \Analog\Handler\Syslog::init ('analog', 'user'); | ||
|
||
$settings = array(); | ||
$settings['log.enabled'] = true; | ||
$settings['log.handler'] = $syslogHandler; | ||
$sherlock = new Sherlock($settings); | ||
$data = $sherlock->getSherlockSettings(); | ||
|
||
$this->assertEquals($syslogHandler, $data['log.handler']); | ||
} | ||
} |