Bash 如何grep symfony2命令中的详细输出?
在我的Bash 如何grep symfony2命令中的详细输出?,bash,symfony,grep,command,output,Bash,Symfony,Grep,Command,Output,在我的app/config/config.yml中,我为独白添加了控制台处理程序: monolog: handlers: console: type: console 因此,当我传递verbosity标志-vvv时,一个命令将生成对monolog的调用的outout,例如: ./bin/console text:hello k0pernikus -vvv [2016-06-01 13:19:27] event.DEBUG: Notified e
app/config/config.yml
中,我为独白添加了控制台处理程序:
monolog:
handlers:
console:
type: console
因此,当我传递verbosity标志-vvv
时,一个命令将生成对monolog的调用的outout,例如:
./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
现在我想通过grep进入第一行
/bin/console text:hello k0pernikus -vvv | grep DebugHandlersListener::configure
但我也得到了第二次调试:
[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"}
我还注意到输出行为奇怪,因为我也无法重定向它:
./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
这似乎是我想要的行为,但我对如何处理冗长的输出有点困惑。我对所有的线路都不感兴趣,只对其中一条线路感兴趣
如何grep一行
我的命令:
<?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");
}
}
I:
问题是日志信息没有写入标准输出,而是写入了错误流。I:
问题是日志信息并没有写入标准输出,而是写入了错误流。您可以检查详细级别并基于此写入输出,这是一个可能的解决方案(我可以发布代码来帮助您)@Rooneyl我不想添加自定义输出。我想grep现有的详细输出。我想这更多地与bash如何处理不同的输出流有关。我不想通过输出代码来解决这个问题。你可以检查详细程度并基于此编写输出,这对你来说是一个可能的解决方案吗(我可以发布代码来帮助你)@Rooneyl我不想添加自定义输出。我想grep现有的详细输出。我想这更多地与bash如何处理不同的输出流有关。我不想通过输出代码来解决这个问题。
./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"}