我正在尝试将CakePHP日志保存在数据库中(table:logs),但在尝试时返回错误:
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));
应用/日志/ 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);
}
}
?>
[编辑]
我更改了DatabaseLogger.php
文件的位置,并添加了两条重要的行:
// app/Lib/Log/Engine/DatabaseLogger.php
App::uses('CakeLogInterface', 'Log');
class DatabaseLogger implements CakeLogInterface {
现在,“工作”,但不像我预期的那样,因为我在写函数中需要更多2个值:query, debug
,但是不允许。我是怎么做到的?
function write($type, $message, $query, $debug) {
答案 0 :(得分:0)
我现在正在这样做:
但我认为这是错误的。
我真正需要的是:“自定义写入功能”,或:“如何创建自定义日志”。
无论如何,谢谢。