diff --git a/src/.env.example b/src/.env.example --- a/src/.env.example +++ b/src/.env.example @@ -16,6 +16,7 @@ SUPPORT_EMAIL= LOG_CHANNEL=stack +LOG_SLOW_REQUESTS=5 DB_CONNECTION=mysql DB_DATABASE=kolabdev diff --git a/src/app/Http/Middleware/RequestLogger.php b/src/app/Http/Middleware/RequestLogger.php --- a/src/app/Http/Middleware/RequestLogger.php +++ b/src/app/Http/Middleware/RequestLogger.php @@ -26,6 +26,13 @@ $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)); + } } } } diff --git a/src/app/OpenVidu/Room.php b/src/app/OpenVidu/Room.php --- a/src/app/OpenVidu/Room.php +++ b/src/app/OpenVidu/Room.php @@ -58,7 +58,15 @@ 'auth' => [ \config('openvidu.api_username'), \config('openvidu.api_password') - ] + ], + 'on_stats' => function (\GuzzleHttp\TransferStats $stats) { + $threshold = \config('logging.slow_log'); + if ($threshold && ($sec = $stats->getTransferTime()) > $threshold) { + $url = $stats->getEffectiveUri(); + $method = $stats->getRequest()->getMethod(); + \Log::warning(sprintf("[STATS] %s %s: %.4f sec.", $method, $url, $sec)); + } + }, ] ); } diff --git a/src/config/logging.php b/src/config/logging.php --- a/src/config/logging.php +++ b/src/config/logging.php @@ -91,4 +91,6 @@ ], ], + 'slow_log' => (float) env('LOG_SLOW_REQUESTS', 5), + ];