Stadionzeitung, Veranstaltungen, News-Artikel, Lightbox und Anzeigen-Verteilung
Stadionzeitung: Live-Seiten (Tabellen, Ergebnisse, Vorschau, Termine, News, Kontakt, Historie, Sportheim, Partner, Momente, Impressum), automatisches Cover, Swipe-Viewer mit Vollbildmodus und die Druckfassung als Falt-Heft. Anzeigen kommen jetzt aus dem Bestand und werden gleichmäßig verteilt, nie mehr als zwei hintereinander (vorher vier Blöcke à fünf). Die Doppelseiten-Regel rechnet das Skript selbst, statt sie von Hand zu prüfen. Veranstaltungen: Bereich /veranstaltungen mit Detailseite pro Fest, Lebenszyklus über das Datum (Ankündigung vor dem Fest, Rückblick danach), Galerie mit Lightbox. veranstaltungen.json ist dritte Termin-Quelle, damit ein Fest nie doppelt gepflegt wird. News-Artikel als dritte dynamische Prefix-Route, gemeinsamer detail-head. Behobene Fehler: - Wappen-Kontexte setzten Zeilen-Layout auf .crest statt auf die Zeile; das Wappen wurde zum Grid, Vereinsname und Tore rutschten darunter zusammen (Ergebnis-Rückblick, Vorschau, Cover). - --header-h (60px) unterschätzt die Kopfleiste um 32px (Logo 72px + 20px Versatz): neues abgeleitetes --header-space, sonst klebten Zurück-Links unter dem Logo. - base_url in der Produktions-Config ohne www, während .htaccess auf www umleitet; preflight prüft das jetzt. - .lightbox brauchte display:none mit (0,2,0), sonst lag das Overlay offen. Neue Werkzeuge: bin/anzeige-add.php (Anzeigen-Bestand), bin/veranstaltung-bilder.php (Plakate und Galerien, Alt-Texte folgen der Quelldatei), bin/qr.php (Druck-QR mit Warnung, wenn base_url nicht auf die echte Domain zeigt). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NzeVVgMCrzCDJAKeLEdKr7
This commit is contained in:
166
bin/logs.php
Normal file
166
bin/logs.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Logübersicht — NUR CLI. Beantwortet in einem Aufruf: läuft alles, und wenn
|
||||
* nicht, was ist zuletzt schiefgegangen? Ersetzt das Durchklicken von fünf
|
||||
* Dateien per FTP.
|
||||
*
|
||||
* Aufruf:
|
||||
* php bin/logs.php Übersicht + letzte Fehler
|
||||
* php bin/logs.php --lines=20 mehr Zeilen je Kanal
|
||||
* php bin/logs.php --errors nur die gesammelte error.log
|
||||
* php bin/logs.php --channel=mail nur einen Kanal, dafür ausführlich
|
||||
* php bin/logs.php --days=30 anderer Auswertungszeitraum (Default 7)
|
||||
*
|
||||
* Format der eigenen Logs (log_write() in helpers.php):
|
||||
* [2026-07-27T08:11:45+00:00] ERROR Meldung
|
||||
* php-errors.log kommt von PHP selbst und hat ein eigenes Format — es wird
|
||||
* mitgezählt, aber nicht nach Level aufgeschlüsselt.
|
||||
*/
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require dirname(__DIR__) . '/app/bootstrap.php';
|
||||
|
||||
$lines = 5;
|
||||
$days = 7;
|
||||
$only = '';
|
||||
$errorsOnly = false;
|
||||
foreach ($argv as $arg) {
|
||||
if (preg_match('/^--lines=(\d+)$/', $arg, $m) === 1) {
|
||||
$lines = max(1, (int) $m[1]);
|
||||
} elseif (preg_match('/^--days=(\d+)$/', $arg, $m) === 1) {
|
||||
$days = max(1, (int) $m[1]);
|
||||
} elseif (preg_match('/^--channel=([a-z0-9-]+)$/', $arg, $m) === 1) {
|
||||
$only = $m[1];
|
||||
$lines = max($lines, 20);
|
||||
} elseif ($arg === '--errors') {
|
||||
$errorsOnly = true;
|
||||
$lines = max($lines, 20);
|
||||
}
|
||||
}
|
||||
|
||||
$logDir = STORAGE_PATH . '/logs';
|
||||
$cutoff = time() - $days * 86400;
|
||||
|
||||
/**
|
||||
* Zeitstempel am Zeilenanfang lesen: `[ISO]` (log_write), `[27-Jul-2026 08:11:45 UTC]`
|
||||
* (PHP selbst) oder ein nackter ISO-Stempel ohne Klammern. Null = kein Zeitstempel,
|
||||
* die Zeile gehört dann zum vorherigen Eintrag (z. B. Stacktrace-Fortsetzung).
|
||||
*/
|
||||
$stampOf = static function (string $line): ?int {
|
||||
if (preg_match('/^\[([^\]]+)\]/', $line, $m) === 1 || preg_match('/^(\d{4}-\d{2}-\d{2}\S*)/', $line, $m) === 1) {
|
||||
$ts = strtotime($m[1]);
|
||||
return $ts === false ? null : $ts;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/** @return string[] */
|
||||
$readLines = static function (string $file): array {
|
||||
if (!is_file($file) || filesize($file) === 0) {
|
||||
return [];
|
||||
}
|
||||
return array_values(array_filter(explode("\n", (string) file_get_contents($file)), static fn ($l) => 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);
|
||||
Reference in New Issue
Block a user