['label' => 'nginx — erreurs', 'path' => '/var/log/nginx/posterg_error.log'], 'nginx_access' => ['label' => 'nginx — accès', 'path' => '/var/log/nginx/posterg_access.log'], 'php_error' => ['label' => 'PHP-FPM — erreurs', 'path' => '/var/log/php8.4-fpm.log'], ]; const ALLOWED_LINES = [50, 100, 200, 500]; // ── Input validation ────────────────────────────────────────────────────────── $selectedKey = $_GET['log'] ?? 'nginx_error'; $selectedN = isset($_GET['n']) ? (int) $_GET['n'] : 100; if (!array_key_exists($selectedKey, LOG_FILES)) { $selectedKey = 'nginx_error'; } if (!in_array($selectedN, ALLOWED_LINES, true)) { $selectedN = 100; } $logDef = LOG_FILES[$selectedKey]; $logPath = $logDef['path']; // ── Read log ────────────────────────────────────────────────────────────────── $lines = null; // null = unavailable, [] = empty, [...] = lines $readError = null; if (!function_exists('exec')) { $readError = "exec() est désactivé sur ce serveur."; } elseif (!file_exists($logPath)) { $readError = "Fichier introuvable : " . htmlspecialchars($logPath); } elseif (!is_readable($logPath)) { $readError = "Fichier non lisible (permissions insuffisantes) : " . htmlspecialchars($logPath); } else { $output = []; $rc = 0; // tail -n N ensures we never load the whole file into memory exec('tail -n ' . intval($selectedN) . ' ' . escapeshellarg($logPath) . ' 2>/dev/null', $output, $rc); if ($rc !== 0) { $readError = "Erreur lors de la lecture du fichier journal."; } else { // Reverse so newest lines appear first $lines = array_reverse($output); } } // ── File metadata ───────────────────────────────────────────────────────────── $fileMeta = null; if (file_exists($logPath)) { $size = filesize($logPath); $mtime = filemtime($logPath); $fileMeta = [ 'size' => $size > 1048576 ? number_format($size / 1048576, 2) . ' MB' : number_format($size / 1024, 1) . ' KB', 'mtime' => date('d/m/Y H:i:s', $mtime), ]; } // ── Log-level classifier (for nginx error log coloring) ─────────────────────── /** * Returns a CSS class based on the log level token in a log line. * nginx error lines look like: 2024/01/15 12:34:56 [error] 1234#1234: … * nginx access lines: 1.2.3.4 - - [15/Jan/2024:12:34:56 +0000] "GET / HTTP/1.1" 200 … */ function logLineClass(string $line): string { // nginx error log: [crit], [error], [warn], [notice], [info], [debug] if (preg_match('/\[(crit|emerg|alert)\]/', $line)) return 'log-crit'; if (preg_match('/\[error\]/', $line)) return 'log-error'; if (preg_match('/\[warn\]/', $line)) return 'log-warn'; if (preg_match('/\[notice\]/', $line)) return 'log-notice'; // access log: highlight HTTP 4xx / 5xx if (preg_match('/" [45]\d\d /', $line)) return 'log-error'; if (preg_match('/" 3\d\d /', $line)) return 'log-notice'; return ''; } require_once APP_ROOT . '/templates/admin/head.php'; ?>

Journaux serveur

Affiché le Rafraîchir

0): ?> ligne(s)
Journaux non disponibles
En environnement de développement, les logs nginx ne sont pas disponibles. Cette page est pleinement fonctionnelle sur le serveur de production.
Le fichier journal est vide.
$line): ?>