function testFileLoggerErrorLevel() { $buffer = fopen('php://memory', 'rw'); $logger = new FileLogger($buffer, ILogger::ERROR); $logger->debug('debug message'); $logger->info('info message'); $logger->error('error message'); $this->assertTrue(rewind($buffer)); $out = fread($buffer, 5000); $this->assertEqual($out, "error message\n"); }
function testFileLogger() { $sep = DIRECTORY_SEPARATOR; $fName = dirname(__FILE__) . $sep . 'data' . $sep . 'general.log'; $this->fl = $logger = new FileLogger($fName, null, Logger::DEVEL); $logger->reset(); $logger->devel('1'); $logger->debug('2'); $logger->info('3'); $logger->warn('4'); $logger->error('5'); $len = filesize($fName); if ($len !== 161) { return "{$len} bytes instead of 161 bytes"; } $len = strlen($logger->get()); if ($len !== 161) { return "{$len} chars instead 161 chars"; } }
<?php $fileLog = new FileLogger('1.txt'); $fileLog->error('This is error'); $dbLog = new DbLogger('localhost', 'root', '', 'learning'); $dbLog->error('This is error');