Created
January 19, 2018 05:53
-
-
Save sarkarshuvojit/4f6a7c11863251bf6830bf58948a36fd to your computer and use it in GitHub Desktop.
Log all queries in a log file - Laravel
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
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
class QueryLog | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
\DB::connection()->enableQueryLog(); | |
$response = $next($request); | |
// Perform action | |
$queries = \DB::getQueryLog(); | |
\Log::useDailyFiles(storage_path().'/logs/queries/query.log'); | |
\Log::info($queries); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment