i have written a Plugin to write the Logs in the Database. My folder structure looks like this:
plugins/Logging/src/Log/Engine/DatabaseLog
The class looks like this:
<?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;
}
}
?>
In my app.php:
'Log' => [
'debug' => [
'className' => 'Logging.DatabaseLog',
]
],
what I need to change so that the class is loaded
Thanks
Please read the section form the official documentation on how to autoload classes from plugins:
http://book.cakephp.org/3.0/en/plugins.html#autoloading-plugin-classes
my Error-Message:
Fatal error: Uncaught exception 'RuntimeException' with message 'Could not load class DatabaseLog' in /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Log/LogEngineRegistry.php:57 Stack trace: #0 /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php(86): Cake\Log\LogEngineRegistry->_throwMissingClassError('DatabaseLog', 'Logging') #1 /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Log/Log.php(198): Cake\Core\ObjectRegistry->load('debug', Array) #2 /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Log/Log.php(180): Cake\Log\Log::_loadConfig() #3 /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Log/Log.php(346): Cake\Log\Log::_init() #4 /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Log/Log.php(448): Cake\Log\Log::write('error', '[RuntimeExcepti...', Array) #5 /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(245): Cake\Log\Log::error('[RuntimeExcepti...') #6 /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(156): Cake\Error\Base in /Users/patrick/Sites/vz/vendor/cakephp/cakephp/src/Log/LogEngineRegistry.php on line 57
If I understand the documentation correctly, I do not need the composer.json. in my bootstrap.php.
bootstrap.php:
Plugin::load('Logging', ['autoload' => true]);
I have yet adjusted the composer.json:
composer.json:
"autoload": {
"psr-4": {
"App\\": "src",
"Logging\\": "./plugins/Logging/src"
}
},
Dunno if any one still needs this. But just in case.
I have encountered this a few times since i started using cake 3.
However, as long as i add this line to the end of my root bootstrap.php
Plugin::load('[Name_of_Plugin]', ['bootstrap' => false, 'routes' => true]);
It always work.
Cheers.