Skip to content

Instantly share code, notes, and snippets.

@caingougou
Created November 28, 2014 03:00
Show Gist options
  • Save caingougou/d84196baccee3a1b6e53 to your computer and use it in GitHub Desktop.
Save caingougou/d84196baccee3a1b6e53 to your computer and use it in GitHub Desktop.
add laravel query to log
Event::listen('illuminate.query', function($query, $bindings, $time, $name) {
$data = compact('bindings', 'time', 'name');
// Format binding data for sql insertion
foreach ($bindings as $i => $binding) {if ($binding instanceof \DateTime) {
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
} else if (is_string($binding)) {
$bindings[$i] = "'$binding'";
}
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
Log::info($query, $data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment