При использовании монолога в командах консоли Symfony все сообщения выводятся на stderr. Как настроить монолог, чтобы отправить все ниже уровня ПРЕДУПРЕЖДЕНИЯ на stdout и все остальное на stderr?Symfony and Monolog - как заставить его отправлять все ниже уровня WARNING на stdout и все остальное на stderr
0
A
ответ
1
easies способ посмотреть, как Монолог (в Symfony на самом деле, от моста) ConsoleHandler работы:
https://github.com/symfony/monolog-bridge/blob/master/Handler/ConsoleHandler.php
/**
* Before a command is executed, the handler gets activated and the console output
* is set in order to know where to write the logs.
*
* @param ConsoleCommandEvent $event
*/
public function onCommand(ConsoleCommandEvent $event)
{
$output = $event->getOutput();
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}
$this->setOutput($output);
}
Таким образом, вы можете расширить и изменить это поведение, чтобы сохранить оба выхода и решить, что использование здесь
https://github.com/symfony/monolog-bridge/blob/master/Handler/ConsoleHandler.php#L153-L160
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
// at this point we've determined for sure that we want to output the record, so use the output's own verbosity
$this->output->write((string) $record['formatted'], false, $this->output->getVerbosity());
}
Например, вы можете проверить $record['level']
и переключить выход вручную. После того, как вы реализуете свой собственный обработчик вы можете настроить его с монологом конфигурации Brige:
http://symfony.com/doc/current/logging/monolog_console.html
# app/config/config.yml
monolog:
handlers:
console:
type: service
id: my_app.monolog.console_handler
Вы читали эту страницу: http://symfony.com/doc/current/logging/monolog_console.html? –
Конечно, да. В нем говорится: «Кроме того, журналы ошибок записываются в вывод ошибки (php: // stderr)». Проблема в том, что это неверно. Я сохраняю stdout в один файл и stderr в другой. Независимо от того, что я выводил с помощью вывода OutputInterface :: writeln, Symfony попадает в первую. Все, что я регистрирую с помощью монолога (включая INFO), заканчивается во втором. – Xander