1
我正试图在cakePHP中实现一个日志系统。现在我有一个问题是“写入”中的方法内容被调用两次。这会导致问题,因为它在我的系统中放置了2个相同类型的日志条目。自定义日志方法
Databaselogger.php在lib /发动机/目录:
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!');
任何人都可以提供一些提示,为什么这可能会发生?谢谢!
我实际上把这个例子从网站本身,他们使用databaselogger.php作为文件名:http://book.cakephp.org/2.0/en/core-libraries/logging.html – Sixthpoint
这也没有解决我遇到的问题。这是另一个奇怪的注释,当我调用debug()时,它实际上解决了这个问题。但没有调用它会导致2日志形式 – Sixthpoint
我认为有一个额外的配置设置,你需要这是不是在文档中。可能在你的配置引导?然而,在文档中没有,你的例子确实遵循cakephp书。 – Brianjs