protected function execute(InputInterface $input, OutputInterface $output) { $start = microtime(true); $logger = new Logger(); $logFile = $logger->getLogFile(); if (!file_exists($logFile) || !is_readable($logFile)) { $output->writeln("Log file {$logFile} not found or not readable!"); } else { $words = $input->getOption('with'); /** @var string[] $words */ $words = $words ? explode(',', $words) : false; /** @var string[] $levels */ $levels = $input->getOption('levels'); $levels = $levels ? explode(',', $levels) : false; $date = $input->getOption('date-from'); $fHandler = fopen($logFile, 'r'); if (!$fHandler) { $output->writeln("Some error happened reading file {$logFile} !"); } else { while (!feof($fHandler)) { $buffer = fgets($fHandler, 4096); if ($data = $logger->decodeLine($buffer)) { $show = (!$date || $data['date'] >= $date) && (!$words || $this->areAnyOfThisWords($words, $buffer)) && (!$levels || in_array($data['level'], $levels)); if ($show) { $output->write($buffer); } } } fclose($fHandler); } } $output->writeln('Done in ' . intval((microtime(true) - $start) * 1000) . ' msec !'); }
public function testLogWrite() { $readConfig = PlainFileLogger::getInstance()->getConfig(); $this->assertEquals($this->testConfig['logger']['path'], $readConfig['logger']['path']); $data = 'This is a logged text'; PlainFileLogger::log('error', $data); $loggedText = file_get_contents($this->loggerFile); $this->assertRegExp("/{$data}\$/", $loggedText); unlink($this->loggerFile); // info level is not logged, so this text wont be in the logger file $data = 'This is a logged text'; PlainFileLogger::log('info', $data); $this->assertFalse(file_exists($this->loggerFile)); }
function error_handler($e) { Logger::error($e); }
public function testConfigRead() { $config = PlainFileLogger::getInstance()->getConfig(); $this->assertEquals($this->testConfig, $config); }