From 1bd24d3a57bf68aa3594f8ec0347297e47b79414 Mon Sep 17 00:00:00 2001 From: aliaxander Date: Fri, 19 Feb 2016 21:04:12 +0300 Subject: [PATCH] OutputLogHandler: filter messages according to verbosity level. --- PHPCI/Command/RunCommand.php | 9 +-------- PHPCI/Logging/OutputLogHandler.php | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/PHPCI/Command/RunCommand.php b/PHPCI/Command/RunCommand.php index c2c352e6..99d895dd 100644 --- a/PHPCI/Command/RunCommand.php +++ b/PHPCI/Command/RunCommand.php @@ -74,14 +74,7 @@ class RunCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; - - // For verbose mode we want to output all informational and above - // messages to the symphony output interface. - if ($input->hasOption('verbose') && $input->getOption('verbose')) { - $this->logger->pushHandler( - new OutputLogHandler($this->output, Logger::INFO) - ); - } + $this->logger->pushHandler(new OutputLogHandler($output)); $running = $this->validateRunningBuilds(); diff --git a/PHPCI/Logging/OutputLogHandler.php b/PHPCI/Logging/OutputLogHandler.php index 4b4c81a4..485e4420 100644 --- a/PHPCI/Logging/OutputLogHandler.php +++ b/PHPCI/Logging/OutputLogHandler.php @@ -10,40 +10,48 @@ namespace PHPCI\Logging; use Monolog\Handler\AbstractProcessingHandler; -use Psr\Log\LogLevel; +use Monolog\Logger; use Symfony\Component\Console\Output\OutputInterface; /** * Class OutputLogHandler outputs the build log to the terminal. + * * @package PHPCI\Logging */ class OutputLogHandler extends AbstractProcessingHandler { + + protected static $levels = array( + OutputInterface::VERBOSITY_QUIET => Logger::ERROR, + OutputInterface::VERBOSITY_NORMAL => Logger::WARNING, + OutputInterface::VERBOSITY_VERBOSE => Logger::NOTICE, + OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO, + OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG, + ); /** * @var OutputInterface */ protected $output; /** + * OutputLogHandler constructor. + * * @param OutputInterface $output - * @param bool|string $level - * @param bool $bubble */ - public function __construct( - OutputInterface $output, - $level = LogLevel::INFO, - $bubble = true - ) { - parent::__construct($level, $bubble); + public function __construct(OutputInterface $output) + { + parent::__construct(static::$levels[$output->getVerbosity()]); + $this->output = $output; } /** * Write a log entry to the terminal. + * * @param array $record */ protected function write(array $record) { - $this->output->writeln((string)$record['formatted']); + $this->output->writeln((string) $record['formatted']); } }