0

我正在尝试将 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
阿帕奇: 2.2
PHP: 5.3.9
MySQL: 5.1

文件

引导程序.php

CakeLog::config('otherFile', array(
    'engine' => 'Databaselogger'
));

用户控制器.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);
    }
 
}
?>

[编辑]
我更改了DatabaseLogger.php文件的位置,并添加了 2 行重要的行:

    // app/Lib/Log/Engine/DatabaseLogger.php

    App::uses('CakeLogInterface', 'Log');
    class DatabaseLogger implements CakeLogInterface {

现在,“工作”,但不像我预期的那样,因为我在 write function: 中需要更多 2 个值query, debug,但不允许。我该怎么做?

    function write($type, $message, $query, $debug) {
4

1 回答 1

0

我目前正在这样做:

  • 连接所有变量并在 $message 参数中发送。
  • 后来,我将其分解并使用这些值

但我认为这是错误的。

我真正需要的是:“自定义写入功能”,或者:“如何创建自定义日志”

总之感谢。

于 2013-02-22T11:14:20.477 回答