【发布时间】:2015-06-24 10:23:15
【问题描述】:
我已经编写了一个插件来将日志写入数据库。我的文件夹结构如下所示:
plugins/Logging/src/Log/Engine/DatabaseLog
类如下所示:
<?php
namespace Logging\Log\Engine;
use Cake\Log\Engine\BaseLog;
use Cake\ORM\TableRegistry;
class DatabaseLog extends BaseLog{
private $Model;
public function __construct(array $config = []){
parent::__construct($config);
}
public function log($level, $message, array $context = []){
//Laden des Models
if(!$context || !array_key_exists('model', $context)){
$context['model'] = 'SystemLogs';
}
$this->Model = TableRegistry::get($context['model']);
$log_data = [
'level' => $level,
'message' => $message
];
$entity = $this->Model->newEntity($log_data);
$this->Model->save($entity);
return true;
}
}
?>
在我的 app.php 中:
'Log' => [
'debug' => [
'className' => 'Logging.DatabaseLog',
]
],
我需要改变什么才能加载类
谢谢
【问题讨论】:
-
嘿帕特里克,你能在问题本身中添加具体错误吗?还可以检查缩进 - 它看起来不正常,这会导致它看起来有点乱,人们可能会因此跳过你的问题。
-
第一眼看起来不错。插件是否已在您的引导程序中加载?
-
并且路径是在composer autoloader中注册的吗?
-
what I need to change so that the class is loaded阅读您收到的错误消息,仔细检查您的作曲家设置,并在必要时调试供应商作曲家自动加载文件并转到“我的文件名错误”/“它没有加载那个namespace"/"命名空间与文件不匹配"/etc.
标签: php cakephp logging plugins cakephp-3.0