예제 #1
0
 /**
  * Tests that we can write using the Console writer. This writer will be set so 
  * that all output is passed to STDOUT so it can be captured using output buffering.
  */
 public function testIfElseStatement()
 {
     //clear any previous configuration (as hierarchy is stored between calls)
     Logger::getHierarchy()->clear();
     $logger = Logger::getLogger('test_logger', array('writers' => array('Console' => array('useMinErrorLevel' => false, 'target' => Console::OUTPUT, 'layout' => array('pattern' => '%if ifValue > 4% %trueValue %else% %elseValue %endif%'))), 'extras' => array('local' => array('ifValue' => 3, 'trueValue' => 'It was more than four', 'elseValue' => 'It was less than four'))));
     ob_start();
     $logger->info('Tester Message');
     $logs = ob_get_clean();
     $this->assertNotEquals('', $logs);
 }
예제 #2
0
 public function testFile()
 {
     //clear any previous configuration (as hierarchy is stored between calls)
     Logger::getHierarchy()->clear();
     $logger = Logger::getLogger('test_logger', array('writers' => array('File' => array('file' => __DIR__ . '/testFile.csv', 'append' => false, 'locking' => true))));
     $logger->info('A Tester Message');
     $logger->close();
     //close this logger instance.
     //open the csv and determine if there is one row in the CSV (where the log has been written.)
     if (($handle = fopen(__DIR__ . '/testFile.csv', 'r')) === false) {
         $this->fail('The CSV file could not be opened, which means it could not be generated');
     }
     //close the handle.
     fclose($handle);
     $this->assertEquals(1, $this->getLines(__DIR__ . '/testFile.csv'));
     //remove the tester csv file.
     if (file_exists(__DIR__ . '/testFile.csv')) {
         unlink(__DIR__ . '/testFile.csv');
     }
 }
예제 #3
0
 public function testWriteObject()
 {
     $object = new \PHPLog\Exception\CompilerException('A Complier Exception', ' %if tester < 3 Hello %else%', 10);
     //clear any previous configuration (as hierarchy is stored between calls)
     Logger::getHierarchy()->clear();
     $logger = Logger::getLogger('test_logger', array('writers' => array('EchoWriter' => array())));
     $logger->addRenderer($object, new CompilerRenderer(), true);
     ob_start();
     $logger->info($object);
     $message = ob_get_clean();
     $this->assertNotEquals('', $message);
 }