Skip to content

Instantly share code, notes, and snippets.

@sineld
Created April 29, 2013 07:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sineld/5480157 to your computer and use it in GitHub Desktop.
Save sineld/5480157 to your computer and use it in GitHub Desktop.
<?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