diff --git a/src/CliProgram/Monolog/ConsoleOutputWithMonolog.php b/src/CliProgram/Monolog/ConsoleOutputWithMonolog.php index de7bbea..615a76e 100644 --- a/src/CliProgram/Monolog/ConsoleOutputWithMonolog.php +++ b/src/CliProgram/Monolog/ConsoleOutputWithMonolog.php @@ -12,6 +12,11 @@ use Symfony\Component\Console\Output\ConsoleOutput; class ConsoleOutputWithMonolog extends ConsoleOutput { use TOutputInterfaceWithMonolog; + /** + * Option pour ne pas écrire un message dans Monolog + */ + public const OPTION_SKIP_MONOLOG = 4096; + /** * @param LoggerInterface $logger The Monolog Logger * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) diff --git a/src/CliProgram/Monolog/TOutputInterfaceWithMonolog.php b/src/CliProgram/Monolog/TOutputInterfaceWithMonolog.php index 2b38455..4fec236 100644 --- a/src/CliProgram/Monolog/TOutputInterfaceWithMonolog.php +++ b/src/CliProgram/Monolog/TOutputInterfaceWithMonolog.php @@ -43,7 +43,7 @@ trait TOutputInterfaceWithMonolog { $messages = [$messages]; } - if ($this->logger !== null) { + if ($this->logger !== null && (($options & ConsoleOutputWithMonolog::OPTION_SKIP_MONOLOG) !== ConsoleOutputWithMonolog::OPTION_SKIP_MONOLOG)) { $verbosities = OutputInterface::VERBOSITY_QUIET | OutputInterface::VERBOSITY_NORMAL | OutputInterface::VERBOSITY_VERBOSE | OutputInterface::VERBOSITY_VERY_VERBOSE | OutputInterface::VERBOSITY_DEBUG; $verbosity = $verbosities & $options ?: OutputInterface::VERBOSITY_NORMAL; diff --git a/tests/Commands/Hello.php b/tests/Commands/Hello.php index acbd3da..1b81bc9 100644 --- a/tests/Commands/Hello.php +++ b/tests/Commands/Hello.php @@ -3,6 +3,7 @@ namespace jrosset\Tests\Commands; use jrosset\CliProgram\BaseCommand; +use jrosset\CliProgram\Monolog\ConsoleOutputWithMonolog; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -26,6 +27,7 @@ class Hello extends BaseCommand { protected function execute (InputInterface $input, OutputInterface $output): int { $output->writeln('Command : ' . __CLASS__, OutputInterface::VERBOSITY_DEBUG); $output->writeln('Hello !'); + $output->writeln('FIN', ConsoleOutputWithMonolog::OPTION_SKIP_MONOLOG); return Command::SUCCESS; } } \ No newline at end of file