Skip to content

Instantly share code, notes, and snippets.

@kapv89
Last active January 8, 2019 15:21
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kapv89/5561365 to your computer and use it in GitHub Desktop.
Save kapv89/5561365 to your computer and use it in GitHub Desktop.
Log Queries in L4
<?php
Event::listen('illuminate.query', function($query, $bindings, $time) {
static $count;
if(App::make('env') === 'local')
{
$logFile = __DIR__.'/../storage/logs/queries';
ob_start();
var_dump($bindings, $query);
$str = ob_get_clean();
if($count === null)
{
File::put($logFile, '');
$count = 1;
}
$msg = $count++ . '---------------------------------------'.PHP_EOL;
$msg .= $str.PHP_EOL;
$msg .= '--------------------------------------------------------------'.PHP_EOL.PHP_EOL;
File::append($logFile, $msg);
}
});
@kapv89
Copy link
Author

kapv89 commented May 11, 2013

Put this in app/start/global.php , and you can view the query-log for a request-response cycle in app/storage/logs/queries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment