我尝试将CakePHP日志保存在数据库(表:日志)中,但尝试时返回错误:
Could not load class Databaselogger
Error: An Internal Error Has Occurred.
Stack Trace
CORE'Cake'Log'LogEngineCollection.php line 42 → LogEngineCollection::_getLogger(string)
CORE'Cake'Log'CakeLog.php line 199 → LogEngineCollection->load(string, array)
APP'Config'bootstrap.php line 31 → CakeLog::config(string, array)
CORE'Cake'Core'Configure.php line 93 → include(string)
CORE'Cake'bootstrap.php line 164 → Configure::bootstrap(boolean)
APP'webroot'index.php line 91 → include(string)
详细信息
CakePHP:2.3
Apache:2.2
PHP:5.3.9
MySQL:5.1
文件
bootstrap.php
CakeLog::config('otherFile', array(
'engine' => 'Databaselogger'
));
UsersController.php
CakeLog::write('info', $this->alias, null, print_r($this->request->data, true));
app/Log/Databaselogger.php
我也在app/Lib/和app/Lib/log中尝试过,但都不起作用
<?php
class Databaselogger extends CakeLog {
function __construct() {
App::import('Model', 'Log');
$this->Log = new Log;
}
function write($type, $message, $query, $debug) {
$this->Log->create();
$log['type'] = ucfirst($type);
$log['message'] = $message;
$log['query'] = $query;
$log['debug'] = $debug;
$log['created'] = date('Y-m-d H:i:s');
$log['modified'] = date('Y-m-d H:i:s');
return $this->Log->save($log);
}
}
?>
[EDIT]
我更改了DatabaseLogger.php
文件的位置,并添加了两行重要内容:
// app/Lib/Log/Engine/DatabaseLogger.php
App::uses('CakeLogInterface', 'Log');
class DatabaseLogger implements CakeLogInterface {
现在,";作品";,但并不像我预期的那样,因为我在写函数query, debug
中需要更多的2个值,但这是不允许的。我是怎么做到的?
function write($type, $message, $query, $debug) {
我目前正在做:
- 连接所有变量并在$message param中发送
- 稍后,我将其分解并使用值
但我认为这是错误的。
我真正需要的是:"自定义写入功能",或者:"如何创建自定义日志"。
不管怎样,谢谢。