0

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");
    }
}
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
  • you could put a check in for the verbosity level and write output based on that, is that a possible solution for you (I can post code to help with that) – Rooneyl Jun 01 '16 at 11:48
  • @Rooneyl I don't want to add custom output. I want to grep the existing verbosity output. I guess it's more to do with how bash handles different outputstreams. I rather not solve this via outputting code. – k0pernikus Jun 01 '16 at 11:53

1 Answers1

3

I found the solution:

./bin/console text:hello k0pernikus -vvv  2>&1 >/dev/null | grep DebugHandlersListener::config
[2016-06-01 13:56:11] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".  {"uid":"885c2f6"}

Problem was that the log information were not written to the standard output but error stream as well.

Community
  • 1
  • 1
k0pernikus
  • 60,309
  • 67
  • 216
  • 347