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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With