Skip to content

Instantly share code, notes, and snippets.

@tdchien
Created November 17, 2016 14:53
Show Gist options
  • Save tdchien/13722dc45c2a99d6beab0d451d277dff to your computer and use it in GitHub Desktop.
Save tdchien/13722dc45c2a99d6beab0d451d277dff to your computer and use it in GitHub Desktop.
Laravel 5 - Log DB query
public function boot(DispatcherContract $events)
{
parent::boot($events);
$path = storage_path().'/logs/query.log';
\Event::listen('illuminate.query', function($sql, $bindings, $time) use($path) {
// Uncomment this if you want to include bindings to queries
//$sql = str_replace(array('%', '?'), array('%%', '%s'), $sql);
//$sql = vsprintf($sql, $bindings);
$time_now = date('Y-m-d H:i:s');
$log = "$time_now : $sql ($time ms)".PHP_EOL;
\File::append($path, $log);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment