Skip to content

Instantly share code, notes, and snippets.

@sineld sineld/global.php
Created Apr 29, 2013

Embed
What would you like to do?
<?php
// app/start/global.php
/*
|--------------------------------------------------------------------------
| Application Error Logger
|--------------------------------------------------------------------------
|
| Here we will configure the error logger setup for the application which
| is built on top of the wonderful Monolog library. By default we will
| build a rotating log file setup which creates a new file each day.
|
*/
//$logFile = 'log-'.php_sapi_name().'.txt';
//Log::useDailyFiles(storage_path().'/logs/'.$logFile);
// Log to the database asynchronously
Log::listen(function($level, $message, $context) {
// Save the php sapi and date, because the closure needs to be serialized
$apiName = php_sapi_name();
$date = new DateTime;
Queue::push(function() use ($level, $message, $context, $apiName, $date) {
DB::insert("INSERT INTO logs (php_sapi_name, level, message, context, created_at) VALUES (?, ?, ?, ?, ?)", array(
$apiName,
$level,
$message,
json_encode($context),
$date
));
});
});
<?php
use Illuminate\Database\Migrations\Migration;
class AppMigrationCreateLogTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('logs', function($t)
{
$t->increments('id');
$t->string('php_sapi_name');
$t->string('level');
$t->text('message');
$t->text('context');
$t->timestamp('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('logs');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.