Is it possible to log a console command`s output to a log file ? For example when a command has:
protected function execute(InputInterface $input, OutputInterface $output)
{
...
$output->writeln('command run');
...
}
How to log the output without modifying the execute method ?
According to Symfony2 documentation:
The Console component doesn't provide any logging capabilities out of the box. Normally, you run console commands manually and observe the output, which is why logging is not provided.
http://symfony.com/doc/2.8/console/logging.html
However you could use service container inside the command:
$logger = $this->getContainer()->get('logger');
And log some events:
$logger->info('Hello: '.$variable);
You should see the logged entries in app/logs/dev.log or app/logs/prod.log.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With