trim($l) !== '')); }; $ago = static function (?int $ts): string { if ($ts === null) { return '—'; } $d = time() - $ts; if ($d < 3600) { return 'vor ' . max(1, (int) round($d / 60)) . ' Min.'; } if ($d < 86400) { return 'vor ' . (int) round($d / 3600) . ' Std.'; } return 'vor ' . (int) round($d / 86400) . ' Tagen'; }; $size = static function (string $file): string { $b = is_file($file) ? (int) filesize($file) : 0; return $b < 1024 ? "{$b} B" : ($b < 1048576 ? round($b / 1024) . ' KB' : round($b / 1048576, 1) . ' MB'); }; $tail = static function (array $all, int $n): array { return array_slice($all, -$n); }; echo "TSV 08 — Logübersicht (" . date('d.m.Y H:i') . ", Auswertung der letzten {$days} Tage)\n\n"; // --- Gesammelte Fehler zuerst: die eine Datei, die zählt --- $errorFile = $logDir . '/error.log'; $errorLines = $readLines($errorFile); $recentErrors = array_values(array_filter($errorLines, static fn ($l) => ($stampOf($l) ?? 0) >= $cutoff)); if ($recentErrors === []) { echo "Keine Fehler in den letzten {$days} Tagen.\n"; } else { echo count($recentErrors) . " Fehler in den letzten {$days} Tagen (storage/logs/error.log):\n"; foreach ($tail($recentErrors, $lines) as $line) { echo ' ' . $line . "\n"; } if (count($recentErrors) > $lines) { echo ' … ' . (count($recentErrors) - $lines) . " weitere\n"; } } if ($errorsOnly) { exit($recentErrors === [] ? 0 : 1); } // --- Kanäle --- $files = glob($logDir . '/*.log') ?: []; $channels = []; foreach ($files as $file) { $name = basename($file, '.log'); if ($name === 'error' || ($only !== '' && $name !== $only)) { continue; } $channels[$name] = $file; } ksort($channels); if ($channels === []) { echo "\nKeine Kanal-Logs gefunden" . ($only !== '' ? " (--channel={$only})" : '') . ".\n"; exit(0); } echo "\n"; printf("%-14s %8s %-14s %s\n", 'KANAL', 'GRÖSSE', 'LETZTER EINTR.', "INFO/WARN/ERROR ({$days}d)"); echo str_repeat('-', 68) . "\n"; $body = []; foreach ($channels as $name => $file) { $all = $readLines($file); $last = null; $counts = ['INFO' => 0, 'WARN' => 0, 'ERROR' => 0]; foreach ($all as $line) { $ts = $stampOf($line); if ($ts !== null) { $last = $ts; } if (($ts ?? 0) >= $cutoff && preg_match('/^\[[^\]]+\]\s+(INFO|WARN|ERROR)\s/', $line, $m) === 1) { $counts[$m[1]]++; } } $level = $name === 'php-errors' ? '(eigenes Format)' : "{$counts['INFO']}/{$counts['WARN']}/{$counts['ERROR']}"; printf("%-14s %8s %-14s %s\n", $name, $size($file), $ago($last), $level); $body[$name] = $tail($all, $lines); } foreach ($body as $name => $tailLines) { echo "\n--- {$name}.log (letzte " . count($tailLines) . ") ---\n"; foreach ($tailLines as $line) { echo $line . "\n"; } } echo "\nRotation: php bin/log-rotate.php · Deploy-Check: php bin/preflight.php\n"; exit($recentErrors === [] ? 0 : 1);