📋 Blockly Logging Checkliste (Crumbforest)
Diese Datei dokumentiert alle notwendigen Schritte, um das serverseitige Logging von Blockly-Terminal-Anfragen über CakePHP 5 erfolgreich zu implementieren und zu debuggen.
✅ Ziel
Nach einem POST an /crumbapi/blockly-terminal soll ein Log-Eintrag im JSONL-Format in tmp/blockly_terminal_log.jsonl geschrieben werden.
🧱 1. Pfadprüfung
🔍 Fehlerquelle
In CakePHP ist ROOT . 'tmp/... falsch, da der Slash (/) fehlt.
✅ Korrekt
$logPath = ROOT . '/tmp/blockly_terminal_log.jsonl';
// oder
$logPath = ROOT . DS . 'tmp' . DS . 'blockly_terminal_log.jsonl';
🛡️ 2. Rechteprüfung
🔍 Warum?
Webserver (www-data) muss Schreibrechte auf das Ziel haben.
✅ Befehle im Container
chmod 777 /var/www/html/tmp
chmod 666 /var/www/html/tmp/blockly_terminal_log.jsonl
chown -R www-data:www-data /var/www/html/tmp
🧪 3. Direkter Schreibtest via PHP (funktioniert!)
php -r 'file_put_contents("/var/www/html/tmp/blockly_terminal_log.jsonl", json_encode(["debug" => "läuft"]) . "\n", FILE_APPEND);'
Ergebnis sichtbar mit:
cat /var/www/html/tmp/blockly_terminal_log.jsonl
🧾 4. CakePHP Debug-Fallback
Füge in BlocklysController::terminal() folgende Zeile ein:
file_put_contents(
'/var/www/html/tmp/fallback_debug.log',
"[LogPath] $logPath\n[ROOT] " . ROOT . "\n[Exists] " . (file_exists($logPath) ? 'yes' : 'no') . "\n",
FILE_APPEND
);
Dann:
cat /var/www/html/tmp/fallback_debug.log
🧼 5. Fehlerquelle file_put_contents
- Rückgabewert prüfen:
$written = file_put_contents(...);
if ($written === false) {
file_put_contents("/var/www/html/tmp/fallback_debug.log", "Fehler beim Schreiben\n", FILE_APPEND);
}
🟢 Ergebnis
Wenn du JSON-Objekte zeilenweise siehst in:
/var/www/html/tmp/blockly_terminal_log.jsonl
... dann läuft es ✅
Stand
Erstellt am: 2025-06-08 20:33:20
Pfad im Container: /var/www/html/tmp/blockly_terminal_log.jsonl