Refs #383 - Set up basic models for logging
This commit is contained in:
parent
3c1e6ea846
commit
b280802644
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class DbBackendAccessLog extends Migration
|
||||||
|
{
|
||||||
|
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('backend_access_log', function(Blueprint $table)
|
||||||
|
{
|
||||||
|
$table->engine = 'InnoDB';
|
||||||
|
$table->increments('id');
|
||||||
|
$table->integer('user_id')->unsigned();
|
||||||
|
$table->string('ip_address')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('backend_access_log');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php namespace Backend\Models;
|
||||||
|
|
||||||
|
use Model;
|
||||||
|
use Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model for logging access to the back-end
|
||||||
|
*/
|
||||||
|
class AccessLog extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string The database table used by the model.
|
||||||
|
*/
|
||||||
|
protected $table = 'backend_access_log';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array Relations
|
||||||
|
*/
|
||||||
|
public $belongsTo = [
|
||||||
|
'user' => ['Backend\Models\User']
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a log record
|
||||||
|
* @param Backend\Models\User $user Admin user
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public static function add($user)
|
||||||
|
{
|
||||||
|
$record = new static;
|
||||||
|
$record->user = $user;
|
||||||
|
$record->ip_address = Request::getClientIp();
|
||||||
|
$record->save();
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
# ===================================
|
||||||
|
# Column Definitions
|
||||||
|
# ===================================
|
||||||
|
|
||||||
|
columns:
|
||||||
|
created_at:
|
||||||
|
label: Date & Time
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
login:
|
||||||
|
relation: user
|
||||||
|
select: @login
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
ip_address:
|
||||||
|
label: IP Address
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
first_name:
|
||||||
|
relation: user
|
||||||
|
select: @first_name
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
last_name:
|
||||||
|
relation: user
|
||||||
|
select: @first_name
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
email:
|
||||||
|
relation: user
|
||||||
|
select: @email
|
||||||
|
searchable: yes
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class DbCmsErrorLog extends Migration
|
||||||
|
{
|
||||||
|
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('cms_error_log', function(Blueprint $table)
|
||||||
|
{
|
||||||
|
$table->engine = 'InnoDB';
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('url')->nullable();
|
||||||
|
$table->string('referer')->nullable();
|
||||||
|
$table->integer('count')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('cms_error_log');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php namespace Cms\Models;
|
||||||
|
|
||||||
|
use Model;
|
||||||
|
use Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model for logging 404 errors
|
||||||
|
*/
|
||||||
|
class ErrorLog extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The database table used by the model.
|
||||||
|
*/
|
||||||
|
protected $table = 'cms_error_log';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array The attributes that aren't mass assignable.
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a log record
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public static function add()
|
||||||
|
{
|
||||||
|
$record = static::firstOrNew([
|
||||||
|
'url' => Request::fullUrl(),
|
||||||
|
'referer' => Request::header('referer'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$record->exists) {
|
||||||
|
$record->count = 1;
|
||||||
|
$record->save();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$record->increment('count');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
# ===================================
|
||||||
|
# Column Definitions
|
||||||
|
# ===================================
|
||||||
|
|
||||||
|
columns:
|
||||||
|
url:
|
||||||
|
label: URL
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
referer:
|
||||||
|
label: Referer
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
count:
|
||||||
|
label: Counter
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class DbSystemTraceLog extends Migration
|
||||||
|
{
|
||||||
|
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('system_trace_log', function(Blueprint $table)
|
||||||
|
{
|
||||||
|
$table->engine = 'InnoDB';
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('level')->nullable()->index();
|
||||||
|
$table->text('message')->nullable();
|
||||||
|
$table->mediumtext('details')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('system_trace_log');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php namespace System\Models;
|
||||||
|
|
||||||
|
use Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model for logging system errors and debug trace messages
|
||||||
|
*/
|
||||||
|
class TraceLog extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The database table used by the model.
|
||||||
|
*/
|
||||||
|
protected $table = 'system_trace_log';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
$record->details = $details;
|
||||||
|
$record->save();
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
# ===================================
|
||||||
|
# Column Definitions
|
||||||
|
# ===================================
|
||||||
|
|
||||||
|
columns:
|
||||||
|
id:
|
||||||
|
label: ID
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
created_at:
|
||||||
|
label: Date & Time
|
||||||
|
searchable: yes
|
||||||
|
|
||||||
|
message:
|
||||||
|
label: Message
|
||||||
|
searchable: yes
|
||||||
Loading…
Reference in New Issue