/** * Logs an event with the output. * * This method will also colorize the message based on priority and withhold * certain logging in case of verbosity or not. * * @param OutputInterface $output * @param LogEvent $event * @param Command $command * * @return void */ public function logEvent(OutputInterface $output, LogEvent $event, Command $command) { $numericErrors = array(LogLevel::DEBUG => 0, LogLevel::NOTICE => 1, LogLevel::INFO => 2, LogLevel::WARNING => 3, LogLevel::ERROR => 4, LogLevel::ALERT => 5, LogLevel::CRITICAL => 6, LogLevel::EMERGENCY => 7); $threshold = LogLevel::ERROR; if ($output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG) { $threshold = LogLevel::DEBUG; } if ($numericErrors[$event->getPriority()] >= $numericErrors[$threshold]) { /** @var Translator $translator */ $translator = $command->getContainer()->offsetGet('translator'); $message = vsprintf($translator->translate($event->getMessage()), $event->getContext()); switch ($event->getPriority()) { case LogLevel::WARNING: $message = '<comment>' . $message . '</comment>'; break; case LogLevel::EMERGENCY: case LogLevel::ALERT: case LogLevel::CRITICAL: case LogLevel::ERROR: $message = '<error>' . $message . '</error>'; break; } $output->writeln(' ' . $message); } }
/** * Logs an event with the output. * * This method will also colorize the message based on priority and withhold * certain logging in case of verbosity or not. * * @param OutputInterface $output * @param LogEvent $event * * @return void. */ public function logEvent(OutputInterface $output, LogEvent $event) { $threshold = \phpDocumentor\Plugin\Core\Log::ERR; if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { $threshold = \phpDocumentor\Plugin\Core\Log::DEBUG; } if ($event->getPriority() <= $threshold) { $message = $event->getMessage(); switch ($event->getPriority()) { case \phpDocumentor\Plugin\Core\Log::WARN: $message = '<comment>' . $message . '</comment>'; break; case \phpDocumentor\Plugin\Core\Log::EMERG: case \phpDocumentor\Plugin\Core\Log::ALERT: case \phpDocumentor\Plugin\Core\Log::CRIT: case \phpDocumentor\Plugin\Core\Log::ERR: $message = '<error>' . $message . '</error>'; break; } $output->writeln(' ' . $message); } }