Log Sql错误Cakephp

时间:2014-07-03 11:24:32

标签: php sql cakephp

我正在使用插件来记录Cakephp-Application中的错误和警告,并且它正在按照预期工作,但我想,如果与我的数据库连接不正常,那么我还需要记录这些错误,但这次是在外部文件中, 想法应该很简单,我调用CaeLog :: write()并在这些方法中(已经被插件重新实现)我会把“try / Catch”,这将有助于我在抛出Exception的情况下,写消息到日志文件。 我的bootstrap.php看起来像这样:` App :: uses('CakeLog','Log');

CakeLog::config('debug', array(
        'engine' => 'File',
        'types' => array('notice', 'info', 'debug'),
        'file' => 'debug',
));

CakeLog::config('fileLog', array(
        'engine' => 'File',
        'types' => array('fileLog'),
        'file' => 'fileLog',
        'scopes' => array('fileLog')
));
 CakeLog::config('default', array(
'engine' => 'DatabaseLogger.DatabaseLog',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency')`

在写方法中我有这个代码

function write($type, $message){
        try {

               //Save In Db
        } catch (Exception $exc) {
//If the save in DB fails call log in fileLog(which has been defined in bootstrap.php)
            CakeLog::write('fileLog', "***************************\n".$exc."\n***************************\n");
        }     
}

现在的问题:我得到一个循环,导致catch块中的调用,它再次尝试保存在db中,如何在没有循环的情况下解决这个问题?

0 个答案:

没有答案