Application Log
Streaming the latest lines from logs/app.log.
null, 'modified' => null, ]; if ($canReadLog) { $logMeta['size'] = filesize($logPath); $logMeta['modified'] = filemtime($logPath); if (isset($_GET['download'])) { header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="app.log"'); header('Content-Length: ' . $logMeta['size']); readfile($logPath); exit; } try { $logEntries = tail_file($logPath, $lineLimit); } catch (RuntimeException $e) { $canReadLog = false; $logError = $e->getMessage(); } } else { $logError = 'The application log file is missing or unreadable.'; } function tail_file(string $path, int $lines): array { $file = new SplFileObject($path, 'r'); $file->seek(PHP_INT_MAX); $lastLine = $file->key(); $startLine = max($lastLine - $lines + 1, 0); $file->seek($startLine); $buffer = []; while (!$file->eof()) { $buffer[] = rtrim($file->current(), "\r\n"); $file->next(); } return $buffer; } $lastUpdated = $logMeta['modified'] ? date('Y-m-d H:i:s', $logMeta['modified']) . ' UTC' : 'Unknown'; $logSizeHuman = $logMeta['size'] !== null ? number_format($logMeta['size'] / 1024, 1) . ' KB' : 'Unknown'; ?>