new TaoLog([ 'appenders' => [ [ 'class' => 'SingleFileAppender', 'threshold' => \common_Logger::DEBUG_LEVEL, 'file' => $dfile, ], [ 'class' => 'SingleFileAppender', 'threshold' => \common_Logger::INFO_LEVEL, 'file' => $ifile, ], [ 'class' => 'SingleFileAppender', 'threshold' => \common_Logger::WARNING_LEVEL, 'file' => $wfile, ], [ 'class' => 'SingleFileAppender', 'threshold' => \common_Logger::ERROR_LEVEL, 'file' => $efile, ], [ 'class' => 'SingleFileAppender', 'threshold' => \common_Logger::FATAL_LEVEL, 'file' => $cfile, ], ] ]) ]); $logger->logDebug('message'); $this->assertEntriesInFile($dfile, 1); $this->assertEntriesInFile($ifile, 0); $this->assertEntriesInFile($wfile, 0); $this->assertEntriesInFile($efile, 0); $this->assertEntriesInFile($cfile, 0); $logger->logInfo('message'); $this->assertEntriesInFile($dfile, 2); $this->assertEntriesInFile($ifile, 1); $this->assertEntriesInFile($wfile, 0); $this->assertEntriesInFile($efile, 0); $this->assertEntriesInFile($cfile, 0); $logger->logWarning('message'); $this->assertEntriesInFile($dfile, 3); $this->assertEntriesInFile($ifile, 2); $this->assertEntriesInFile($wfile, 1); $this->assertEntriesInFile($efile, 0); $this->assertEntriesInFile($cfile, 0); $logger->logError('message'); $this->assertEntriesInFile($dfile, 4); $this->assertEntriesInFile($ifile, 3); $this->assertEntriesInFile($wfile, 2); $this->assertEntriesInFile($efile, 1); $this->assertEntriesInFile($cfile, 0); $logger->logAlert('message'); $this->assertEntriesInFile($dfile, 5); $this->assertEntriesInFile($ifile, 4); $this->assertEntriesInFile($wfile, 3); $this->assertEntriesInFile($efile, 2); $this->assertEntriesInFile($cfile, 1); //destroy logger object to release files unset($logger); unlink($dfile); unlink($ifile); unlink($wfile); unlink($efile); unlink($cfile); } public function testLogTags() { $dfile = tempnam(sys_get_temp_dir(), "logtest"); $this->assertEntriesInFile($dfile, 0); $logger = new LoggerService([ 'logger' => new TaoLog([ 'appenders' => [ [ 'class' => 'SingleFileAppender', 'threshold' => \common_Logger::DEBUG_LEVEL, 'file' => $dfile, 'tags' => 'CORRECTTAG' ], ] ]) ]); $logger->logDebug('message'); $this->assertEntriesInFile($dfile, 0); $logger->logDebug('message', ['WRONGTAG']); $this->assertEntriesInFile($dfile, 0); $logger->logDebug('message', ['CORRECTTAG']); $this->assertEntriesInFile($dfile, 1); $logger->logDebug('message', ['WRONGTAG', 'CORRECTTAG']); $this->assertEntriesInFile($dfile, 2); $logger->logDebug('message', ['WRONGTAG', 'WRONGTAG2']); $this->assertEntriesInFile($dfile, 2); //destroy logger object to release files unset($logger); unlink($dfile); } public function assertEntriesInFile($pFile, $pCount) { if (file_exists($pFile)) { $count = count(file($pFile)); } else { $count = 0; } $this->assertEquals($count, $pCount, 'Expected count ' . $pCount . ', had ' . $count . ' in file ' . $pFile); } }