1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Http/Middleware/QueryLogging.php

49 lines
1.1 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
2017-01-30 20:40:43 +01:00
namespace App\Http\Middleware;
use Closure;
use DB;
use Illuminate\Http\Request;
use Log;
use Utils;
/**
2017-01-30 20:40:43 +01:00
* Class QueryLogging.
*/
class QueryLogging
{
/**
* Handle an incoming request.
*
2017-01-30 20:40:43 +01:00
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
// Enable query logging for development
if (Utils::isNinjaDev()) {
DB::enableQueryLog();
2016-09-25 20:13:14 +02:00
$timeStart = microtime(true);
}
$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);
}
}
return $response;
}
}