Zend Framework - ZFDebug - 日志 - 记录自定义错误 [英] Zend Framework - ZFDebug - Log - Log Custom Errors

查看:34
本文介绍了Zend Framework - ZFDebug - 日志 - 记录自定义错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ZFDebug 时,是否可以将自定义消息添加到日志"选项卡?

When using ZFDebug, is it possible to add custom messages to the 'Log' tab?

所以你可以使用类似的东西:

So you could use something like:

$this->log('Error: Couldn't find the user');

有没有人设法做到这一点?

Has anyone managed to achieve this?

推荐答案

我以前从未使用过 ZFDebug 并且不知道它.你的帖子激起了我的兴趣,所以我安装了它并一直试图实现你想要做的.我可能会将它添加到我的开发工具箱中,因为我经常使用 ZF.

I have never used ZFDebug before and wasn't aware of it. Your post piqued my interest, so I installed it and have been trying to achieve what you want to do. I will probably add it to my dev toolbox as I use ZF a lot.

您可以通过使用 ZFDebug_Controller_Plugin_Debug_Plugin_Log 需要两个参数.第一个是您要发送的消息,第二个是布尔值,当设置为 true(默认为 false)时,会将您的消息发送到日志"选项卡.

You can achieve what you want by using the mark() method of ZFDebug_Controller_Plugin_Debug_Plugin_Log which takes two arguments. The first is the message you want to send and the second is a boolean which, when set to true (default is false), will send your message to the 'log' tab.

以下代码对我有用:-

$debug = Zend_Controller_Front::getInstance()
             ->getPlugin('ZFDebug_Controller_Plugin_Debug');
$logger = $debug->getPlugin('log');
$logger->mark('Logging a message now', true);

或者使用您的示例(修复了语法错误:))

Or to use your example (with the syntax error fixed :) )

$logger->mark("Error: Couldn't find the user", true);

如您所见,这产生了所需的输出:-

As you can see this produced the desired output:-

我知道并不像你想要的那么简单,但它很接近,你总是可以将它包装在一个函数中.

Not quite as simple as you wanted, I know, but it's close and you could always wrap it in a function.

这篇关于Zend Framework - ZFDebug - 日志 - 记录自定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆