Created
October 9, 2013 15:02
-
-
Save feelinc/6902689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
)); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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