2014-07-29 20:07:20 +10:00
|
|
|
<?php namespace System\Models;
|
|
|
|
|
|
|
|
use Model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Model for logging system errors and debug trace messages
|
|
|
|
*/
|
2014-07-30 17:18:59 +10:00
|
|
|
class EventLog extends Model
|
2014-07-29 20:07:20 +10:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The database table used by the model.
|
|
|
|
*/
|
2014-07-30 17:18:59 +10:00
|
|
|
protected $table = 'system_event_logs';
|
2014-07-29 20:07:20 +10:00
|
|
|
|
2014-07-31 19:35:51 +10:00
|
|
|
/**
|
|
|
|
* @var array List of attribute names which are json encoded and decoded from the database.
|
|
|
|
*/
|
|
|
|
protected $jsonable = ['details'];
|
|
|
|
|
2014-07-29 20:07:20 +10:00
|
|
|
/**
|
|
|
|
* Creates a log record
|
|
|
|
* @param string $message Specifies the message text
|
|
|
|
* @param string $level Specifies the logging level
|
|
|
|
* @param string $details Specifies the error details string
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public static function add($message, $level = 'info', $details = null)
|
|
|
|
{
|
|
|
|
$record = new static;
|
|
|
|
$record->message = $message;
|
|
|
|
$record->level = $level;
|
2014-07-31 19:35:51 +10:00
|
|
|
|
|
|
|
if ($details !== null)
|
|
|
|
$record->details = (array) $details;
|
|
|
|
|
2014-07-29 20:07:20 +10:00
|
|
|
$record->save();
|
|
|
|
|
|
|
|
return $record;
|
|
|
|
}
|
|
|
|
|
2014-07-31 19:35:51 +10:00
|
|
|
/**
|
|
|
|
* Beautify level value.
|
|
|
|
* @param string $level
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLevelAttribute($level)
|
|
|
|
{
|
|
|
|
return ucfirst($level);
|
|
|
|
}
|
|
|
|
|
2014-07-29 20:07:20 +10:00
|
|
|
}
|