ConsoleOutputWithMonolog: add option to skip writing in Monolog

2.x 1.3.1
Julien Rosset 2 years ago
parent 183e7ddd24
commit 18bd10bc39

@ -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)

@ -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;

@ -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;
}
}
Loading…
Cancel
Save