In my app/config/config.yml
I have added the console handler for monolog:
monolog:
handlers:
console:
type: console
So when I pass the verbosity flag -vvv
, a command produces the outout of the calls to monolog, e.g.:
./bin/console text:hello k0pernikus -vvv
[2016-06-01 13:19:27] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". {"uid":"c1e943a"}
[2016-06-01 13:19:27] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". {"uid":"c1e943a"}
Ipsum lorem dolorem
Hello k0pernikus!
Ipsum lorem dolorem
Now I want to grep for the first line via
/bin/console text:hello k0pernikus -vvv | grep DebugHandlersListener::configure
yet I get the second DEBUG too:
[2016-06-01 13:21:17] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". {"uid":"9e84992"}
[2016-06-01 13:21:17] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". {"uid":"9e84992"}
I also notice that the output behaves strange as I also cannot redirect it:
./bin/console text:hello k0pernikus -vvv > fnord
[2016-06-01 13:22:13] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". {"uid":"f21ef6f"}
[2016-06-01 13:22:13] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". {"uid":"f21ef6f"}
cat fnord
Ipsum lorem dolorem
Hello k0pernikus!
Ipsum lorem dolorem
This seems to be wanted behavior, yet I am a bit confused on how to work with the verbosity output. I am not interested in all lines, just in one of them.
How to grep for one line?
My command:
<?php
namespace Kopernikus\ApiBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* PlainTextHelloWorldCommand
**/
class PlainTextHelloWorldCommand extends Command
{
/**
*
*/
protected function configure()
{
$this
->setName('text:hello')
->addArgument('reciever', InputArgument::REQUIRED, 'Who do you want to greet?');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$reciever = $input->getArgument('reciever');
$output->writeln("Ipsum lorem dolorem");
$output->writeln("Hello {$reciever}!");
$output->writeln("Ipsum lorem dolorem");
}
}