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:
Samuel Georges 2015-08-01 11:15:17 +10:00
parent 5c736df2ee
commit aaebea4716
2 changed files with 16 additions and 3 deletions

View File

@ -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);
}
});

View File

@ -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