Created
January 17, 2015 13:32
-
-
Save syossan27/59ffe19272a78963d623 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
LogSql::useFiles(storage_path().'/logs/laravel_sql.log'); | |
Event::listen('illuminate.query', function($query, $bindings, $time, $name) | |
{ | |
$data = compact('bindings', 'time', 'name'); | |
foreach ($bindings as $i => $binding) | |
{ | |
if($binding instanceof \DateTime) | |
{ | |
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\''); | |
}elseif(is_string($binding)){ | |
$bindings[$i] = "'$binding'"; | |
} | |
} | |
$query = str_replace(array('%', '?'), array('%%', '%s'), $query); | |
$query = vsprintf($query, $bindings); | |
LogSql::info($query, $data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment