2013-05-10 131 views
0

我已经设置错误级别为1config.php。 但问题是,我得到很多错误,是NOT ACTUALLY ERRORS in terms of application logicCodeigniter错误日志

考虑下面的代码示例

$deleted = @unlink($filename); 

    $imap_uid = @imap_uid($con,$msgno); 

正如你可以看到,上面的例子不会抛出错误,但是如果出现错误笨会记录。

是否可以动态禁用错误日志记录?

我期待这样的事情

// .... 

    $this->error_log = 0; // disable error logging 

    //Perform some operation that which may log an error,even its suppressed 

    $this->error_log = 1; //enable it again 

// ... 

感谢。

回答

1

可以扩展CI_Log类中添加setter方法$ _enabled

Class MY_Log extends CI_Log 
{ 
    function enable_logging($item=TRUE) { 
     $this->_enabled = (bool)$item; 
    } 
} 

现在你可以做这样的

$这个 - >对数> enable_logging(FALSE); //禁用

$ this-> log-> enable_logging(); //启用

+0

感谢..它的工作.. – Red 2013-05-10 09:07:45

0

感谢Michail的回答,我有这个更灵活的解决方案,使用受保护的$ _threshold变量。

Class MY_Log extends CI_Log 
{ 
    public function setThreshold($l){ 
    if(!in_array($l,array(0,1,2,3,4,5))){ 
     log_message("error","MY_Log->setThreshold unsupported val: " . $l); 
     return false; 
    } 
    $this->_threshold = $l; 
    return true; 
    } 
} 

从你的控制器,你做

$this->log->setThreshold(0);