我正在尝试在 cakePHP 中实现日志系统。我现在有一个问题,“write”中的方法内容被调用了两次。这会导致问题,因为它在我的系统中放置了 2 个相同类型的日志条目。
Lib/Engine/ 目录下的 Databaselogger.php:
App::uses('CakeLogInterface', 'Log');
class DatabaseLogger implements CakeLogInterface {
private $types = array();
public function __construct($options = array()) {
// Allowed method calls
$this->types = $options['types'];
}
public function write($type = NULL, $message = NULL) {
// Only store to cache types that are permitted, other errors from cake are not reported
if(!empty($this->types) && in_array($type, $this->types))
{
//make database entry here
}
}
}
在我的 bootstrap.php 中:
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
// Custom configuration
CakeLog::config('mytest', array(
'engine' => 'DatabaseLogger',
'types' => array('mytest'),
'scope' => array(),
'file' => '',
));
这就是我调用该方法的方式:
CakeLog::write('mytest', 'this message!');
任何人都可以就为什么会发生这种情况给出一些提示吗?谢谢!