public function testProvidingNullLineFormatToGetMonologDefault() { $logfileName = 'nullFormatterTest.log'; $this->cleanUpLogFile($logfileName); $command = $this->registerCommand(new LoggingCommand()); EncapsulationViolator::invokeMethod($command, 'setLogFilename', array($logfileName)); EncapsulationViolator::invokeMethod($command, 'setConsoleLogLineFormat', array(null)); EncapsulationViolator::invokeMethod($command, 'setFileLogLineFormat', array(null)); $commandTester = $this->executeCommand($command); // Generate what the default format looks like $lineFormatter = new \Monolog\Formatter\LineFormatter(null); $record = array('message' => 'The quick brown fox jumps over the lazy dog', 'context' => array(), 'level' => Logger::EMERGENCY, 'level_name' => Logger::getLevelName(Logger::EMERGENCY), 'channel' => $command->getLogger()->getName(), 'datetime' => new \DateTime('1970-01-01 00:00:00'), 'extra' => array()); $exampleLine = $lineFormatter->format($record); $exampleLine = trim(str_replace('[1970-01-01 00:00:00]', '', $exampleLine)); // strip out date as this wont match // Test console format $this->assertRegExp('/' . $exampleLine . '/', $commandTester->getDisplay(), 'Console log line format does not seem to match the Monolog default'); // Test default logfile format $this->assertRegExp('/' . $exampleLine . '/', $this->getLogfileContents($logfileName), 'File log line format does not seem to match the Monolog default'); $this->cleanUpLogFile($logfileName); }
public function format(array $record) { $record['padded_level'] = str_pad($record['level_name'], 8); $record['message'] = str_replace("\n", "\n ", $record['message']); $output = parent::format($record); if (dbsteward::$ENABLE_COLOR) { $c = new Color($output); switch ($record['level']) { case Logger::DEBUG: $c->dark_gray(); break; case Logger::WARNING: $c->yellow(); break; case Logger::ERROR: $c->red(); break; } return $c . PHP_EOL; } else { return $output . PHP_EOL; } }