Page MenuHomePhorge

RequestLogger.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

RequestLogger.php

<?php
namespace App\Http\Middleware;
use Closure;
class RequestLogger
{
private static $start;
public function handle($request, Closure $next)
{
// FIXME: This is not really a request start, but we can't
// use LARAVEL_START constant when working with swoole
self::$start = microtime(true);
return $next($request);
}
public function terminate($request, $response)
{
if (\config('app.debug')) {
if (empty($response->noLogging)) {
$url = $request->fullUrl();
$method = $request->getMethod();
$mem = round(memory_get_peak_usage() / 1024 / 1024, 1);
$time = microtime(true) - self::$start;
\Log::debug(sprintf("C: %s %s [%sM]: %.4f sec.", $method, $url, $mem, $time));
}
} else {
$threshold = \config('logging.slow_log');
if ($threshold && ($time = microtime(true) - self::$start) > $threshold) {
$url = $request->fullUrl();
$method = $request->getMethod();
\Log::warning(sprintf("[STATS] %s %s: %.4f sec.", $method, $url, $time));
}
}
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 1:23 PM (1 d, 13 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18858706
Default Alt Text
RequestLogger.php (1 KB)

Event Timeline