mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Tidy up the DB Event logger, add failsafe
If there is a problem with the Model, don't try to log with a broken model (infinite loop), this can be confirmed by checking if the Model class alias exists
This commit is contained in:
parent
5c736df2ee
commit
aaebea4716
@ -6,7 +6,6 @@ use Event;
|
||||
use Config;
|
||||
use Backend;
|
||||
use Request;
|
||||
use DbDongle;
|
||||
use Validator;
|
||||
use BackendMenu;
|
||||
use BackendAuth;
|
||||
@ -244,7 +243,7 @@ class ServiceProvider extends ModuleServiceProvider
|
||||
protected function registerLogging()
|
||||
{
|
||||
Event::listen('illuminate.log', function ($level, $message, $context) {
|
||||
if (DbDongle::hasDatabase() && !defined('OCTOBER_NO_EVENT_LOGGING')) {
|
||||
if (EventLog::useLogging()) {
|
||||
EventLog::add($message, $level);
|
||||
}
|
||||
});
|
||||
|
@ -1,7 +1,8 @@
|
||||
<?php namespace System\Models;
|
||||
|
||||
use Str;
|
||||
use Model;
|
||||
use DbDongle;
|
||||
use October\Rain\Database\Model;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
@ -22,6 +23,19 @@ class EventLog extends Model
|
||||
*/
|
||||
protected $jsonable = ['details'];
|
||||
|
||||
/**
|
||||
* Returns true if this logger should be used.
|
||||
* @return bool
|
||||
*/
|
||||
public static function useLogging()
|
||||
{
|
||||
return (
|
||||
class_exists('Model') &&
|
||||
DbDongle::hasDatabase() &&
|
||||
!defined('OCTOBER_NO_EVENT_LOGGING')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a log record
|
||||
* @param string $message Specifies the message text
|
||||
|
Loading…
x
Reference in New Issue
Block a user