2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
2016-05-13 11:08:41 +02:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
2016-05-13 11:08:41 +02:00
|
|
|
use DB;
|
2016-07-03 18:11:58 +02:00
|
|
|
use Illuminate\Http\Request;
|
2016-05-13 11:08:41 +02:00
|
|
|
use Log;
|
|
|
|
use Utils;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class QueryLogging.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2016-05-13 11:08:41 +02:00
|
|
|
class QueryLogging
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2017-01-30 20:40:43 +01:00
|
|
|
* @param Request $request
|
|
|
|
* @param Closure $next
|
|
|
|
*
|
2016-05-13 11:08:41 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-07-03 18:11:58 +02:00
|
|
|
public function handle(Request $request, Closure $next)
|
2016-05-13 11:08:41 +02:00
|
|
|
{
|
|
|
|
// Enable query logging for development
|
|
|
|
if (Utils::isNinjaDev()) {
|
|
|
|
DB::enableQueryLog();
|
2016-09-25 20:13:14 +02:00
|
|
|
$timeStart = microtime(true);
|
2016-05-13 11:08:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$response = $next($request);
|
|
|
|
|
|
|
|
if (Utils::isNinjaDev()) {
|
|
|
|
// hide requests made by debugbar
|
|
|
|
if (strstr($request->url(), '_debugbar') === false) {
|
|
|
|
$queries = DB::getQueryLog();
|
|
|
|
$count = count($queries);
|
2016-09-25 20:13:14 +02:00
|
|
|
$timeEnd = microtime(true);
|
|
|
|
$time = $timeEnd - $timeStart;
|
|
|
|
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
|
2016-09-01 19:02:37 +02:00
|
|
|
//Log::info($queries);
|
2016-05-13 11:08:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|