Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Middleware/RequestLogger.php
Show All 13 Lines | public function handle($request, Closure $next) | ||||
// use LARAVEL_START constant when working with swoole | // use LARAVEL_START constant when working with swoole | ||||
self::$start = microtime(true); | self::$start = microtime(true); | ||||
return $next($request); | return $next($request); | ||||
} | } | ||||
public function terminate($request, $response) | public function terminate($request, $response) | ||||
{ | { | ||||
if (\App::environment('local')) { | if (\App::environment(['local', 'testing'])) { | ||||
$url = $request->fullUrl(); | $url = $request->fullUrl(); | ||||
$method = $request->getMethod(); | $method = $request->getMethod(); | ||||
$mem = round(memory_get_peak_usage() / 1024 / 1024, 1); | $mem = round(memory_get_peak_usage() / 1024 / 1024, 1); | ||||
$time = microtime(true) - self::$start; | $time = microtime(true) - self::$start; | ||||
\Log::debug(sprintf("C: %s %s [%sM]: %.4f sec.", $method, $url, $mem, $time)); | \Log::debug(sprintf("C: %s %s [%sM]: %.4f sec.", $method, $url, $mem, $time)); | ||||
} else { | } else { | ||||
$threshold = \config('logging.slow_log'); | $threshold = \config('logging.slow_log'); | ||||
if ($threshold && ($time = microtime(true) - self::$start) > $threshold) { | if ($threshold && ($time = microtime(true) - self::$start) > $threshold) { | ||||
$url = $request->fullUrl(); | $url = $request->fullUrl(); | ||||
$method = $request->getMethod(); | $method = $request->getMethod(); | ||||
\Log::warning(sprintf("[STATS] %s %s: %.4f sec.", $method, $url, $time)); | \Log::warning(sprintf("[STATS] %s %s: %.4f sec.", $method, $url, $time)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |