Created
November 17, 2016 14:53
-
-
Save tdchien/13722dc45c2a99d6beab0d451d277dff to your computer and use it in GitHub Desktop.
Laravel 5 - Log DB query
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
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