Commit b506859d authored by Taddeüs Kroes's avatar Taddeüs Kroes

Adapted logger + unit tests to work on Linux.

parent 20bfea03
...@@ -24,7 +24,7 @@ class Logger extends Base { ...@@ -24,7 +24,7 @@ class Logger extends Base {
const INFO = 3; const INFO = 3;
const DEBUG = 4; const DEBUG = 4;
static $level_names = array('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'); static $level_names = array('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG');
private static $allowed_dump_formats = array('plain', 'html', 'file'); private static $allowed_dump_formats = array('plain', 'html', 'file', 'none');
const DEFAULT_FORMAT = '%(datetime): %(level): %(message)'; const DEFAULT_FORMAT = '%(datetime): %(level): %(message)';
...@@ -136,6 +136,8 @@ class Logger extends Base { ...@@ -136,6 +136,8 @@ class Logger extends Base {
function dump($file_prefix='log') { function dump($file_prefix='log') {
switch( $this->dump_format ) { switch( $this->dump_format ) {
case 'none':
return;
case 'plain': case 'plain':
echo $this->dumps(); echo $this->dumps();
break; break;
...@@ -154,7 +156,7 @@ class Logger extends Base { ...@@ -154,7 +156,7 @@ class Logger extends Base {
function save($path) { function save($path) {
if( $this->log_directory && !is_dir($this->log_directory) ) if( $this->log_directory && !is_dir($this->log_directory) )
mkdir($this->log_directory, 0644, true); mkdir($this->log_directory, 0777, true);
file_put_contents($this->log_directory . $path, $this->dumps()); file_put_contents($this->log_directory . $path, $this->dumps());
} }
......
...@@ -173,23 +173,9 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase { ...@@ -173,23 +173,9 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
$this->assertRegExp('/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename); $this->assertRegExp('/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename);
} }
/**
* @depends test_dump_file_regular
*/
function test_dump_file_prefix() {
$this->logger->set_directory(LOGDIR);
$this->logger->set_dump_format('file');
$this->logger->warning('test message');
$this->logger->dump('error');
$filename = $this->find_logfile();
$this->assertStringEqualsFile(LOGDIR . $filename, 'WARNING: test message');
unlink(LOGDIR . $filename);
$this->assertRegExp('/^error_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename);
}
function test_handle_exception() { function test_handle_exception() {
$this->logger->handle_exception(new Exception('test message')); $this->logger->set_dump_format('none');
$this->logger->handle_exception(new RuntimeException('test message'));
$this->assertNotEquals($this->logger->dumps(), ''); $this->assertNotEquals($this->logger->dumps(), '');
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment