Understanding the issue of efficient debugging, you can always print debugging messages using echo or var_dump
If you plan to use a command without a Symfony application with global debugging messages, here is a way to do it.
Symfony offers 3 different OutputInterface s
Debug to file
By doing this, whenever you call $output->writeln() on your command, it will write a new line in /path/to/debug/file.log
use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Input\ArrayInput; use Acme\FooBundle\Command\MyCommand; $params = array(); $input = new ArrayInput($params); $file = '/path/to/debug/file.log'; $handle = fopen($file, 'w+'); $output = new StreamOutput($handle); $command = new MyCommand; $command->run($input, $output); fclose($handle);
Debugging in the console
This is the same process, except that you use ConsoleOutput instead
use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Input\ArrayInput; use Acme\FooBundle\Command\MyCommand; $params = array(); $input = new ArrayInput($params); $output = new ConsoleOutput(); $command = new MyCommand; $command->run($input, $output);
No debugging
No message will be printed
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Input\ArrayInput; use Acme\FooBundle\Command\MyCommand; $params = array(); $input = new ArrayInput($params); $output = new NullOutput(); $command = new MyCommand; $command->run($input, $output);
Touki source share