I'd like Symfony to log the Doctrine SQL queries that one of my tasks executes to a log file, much like the web debug toolbar does for non-cli code. Is this possible?
Here's some example code for a task. I would like the SELECT query to be logged in a similar way to how it would be if it was called from an action.
class exampleTask extends sfBaseTask
{
protected function configure()
{
parent::configure();
$this->namespace = 'test';
$this->name = 'example';
}
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$users = Doctrine_Core::getTable('SfGuardUser')
->createQuery('s')
->select('s.first_name')
->execute();
foreach($users as $user) {
print $user->getFirstName()."\n";
}
}
}
Try using the global task option --trace
(shortcut -t
). Like:
./symfony --trace namespace:task
It logs database queries the moment they are executed.
Don't forget to enable logging in the settings.yml of the application you're running the task in.
So if you're running the task in the dev
environment of the backend you would edit apps/backend/config/settings.yml
:
dev:
.settings:
logging_enabled: true
Note that this also logs stack traces of exception which might also be very helpful if you need to debug your tasks.
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