从 Symfony 1.4 任务记录 Doctrine 查询
我希望 Symfony 将我的任务之一执行的 Doctrine SQL 查询记录到日志文件中,就像 Web 调试工具栏对非 cli 代码所做的那样。这可能吗?
- Symfony 版本:1.4.12
- Doctrine 版本:1.2.4
下面是任务的一些示例代码。我希望 SELECT 查询的记录方式与从操作中调用它的方式类似。
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";
}
}
}
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?
- Symfony version: 1.4.12
- Doctrine version: 1.2.4
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";
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用全局任务选项
--trace
(快捷方式-t
)。就像:它在执行数据库查询时记录它们。
不要忘记在您运行任务的应用程序的 settings.yml 中启用日志记录。
因此,如果您在
dev
环境中运行任务您要编辑的后端apps/backend/config/settings.yml
:请注意,这还会记录异常的堆栈跟踪,如果您需要调试任务,这也可能非常有用。
Try using the global task option
--trace
(shortcut-t
). Like: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 editapps/backend/config/settings.yml
:Note that this also logs stack traces of exception which might also be very helpful if you need to debug your tasks.
如果您打开日志记录,所有查询都应记录到您的应用程序日志的
log
目录中。为此,请在settings.yml
中将logging_enabled
设置为true
。然后,您可以在日志文件上使用
tail -f
来查看发生了什么。If you turn logging on all queries should be logged to your application log in the
log
directory. To do this setlogging_enabled
totrue
in yoursettings.yml
.You can then
tail -f
on the logfile and see what's going on.