Logging konfigurierbar via WEBDAV_LOG; DEBUG entfernt

- WEBDAV_LOG=debug|error|off steuert Datei-Logging
- DEBUG durch WEBDAV_LOG in server.js ersetzt
- .env.example: WEBDAV_LOG-Doku
- Doku: Troubleshooting mit WEBDAV_LOG=debug

Made-with: Cursor
This commit is contained in:
2026-02-28 16:28:09 +01:00
parent b463579896
commit 19dd30e0fb
3 changed files with 17 additions and 10 deletions

View File

@@ -9,7 +9,10 @@ CRYPTO_SECRET=6KYQBP847D4ATSFA
# Für Namensentschlüsselung (CRYPTO_SECRET2). Falls nicht gesetzt, wird CRYPTO_SECRET verwendet. # Für Namensentschlüsselung (CRYPTO_SECRET2). Falls nicht gesetzt, wird CRYPTO_SECRET verwendet.
# CRYPTO_SECRET2=6KYQBP847D4ATSFA # CRYPTO_SECRET2=6KYQBP847D4ATSFA
# DEBUG=1 # Salt-Decryption testen; PUT-Logging (Pfad, Body-Größe, Stacktrace bei Fehlern) # DEBUG=1 # Salt-Decryption testen; Stacktrace bei PUT-Fehlern
# WEBDAV_LOG=debug # REQ/RES, PUT-Schritte, Fehler → logs/webdav-debug.log, webdav-errors.log
# WEBDAV_LOG=error # Nur Fehler → logs/webdav-errors.log
# WEBDAV_LOG=off # Kein Datei-Logging (Standard)
# Browser-Token (für token-test.js und WebDAV) aus drive.internxt.com localStorage # Browser-Token (für token-test.js und WebDAV) aus drive.internxt.com localStorage
# INXT_TOKEN= # xNewToken # INXT_TOKEN= # xNewToken

View File

@@ -94,7 +94,7 @@ Der Server erstellt fehlende Ordner rekursiv (MKCOL). Bei 500-Fehlern: Server-Lo
1. **Port prüfen:** rclone-URL muss exakt dem Server-Port entsprechen. Steht in der Konsole z.B. `http://127.0.0.1:3010`, dann in rclone `url = http://127.0.0.1:3010` eintragen. 1. **Port prüfen:** rclone-URL muss exakt dem Server-Port entsprechen. Steht in der Konsole z.B. `http://127.0.0.1:3010`, dann in rclone `url = http://127.0.0.1:3010` eintragen.
2. **Nur einen Server:** `npm start` beenden (Ctrl+C), dann nur `scripts\start-webdav.cmd` nutzen sonst antwortet evtl. ein alter Prozess. 2. **Nur einen Server:** `npm start` beenden (Ctrl+C), dann nur `scripts\start-webdav.cmd` nutzen sonst antwortet evtl. ein alter Prozess.
3. **rclone config:** `rclone config` → Remote `internxt-webdav` → `url` = `http://127.0.0.1:PORT` (PORT aus Server-Start). 3. **rclone config:** `rclone config` → Remote `internxt-webdav` → `url` = `http://127.0.0.1:PORT` (PORT aus Server-Start).
4. **Logs:** `logs\webdav-errors.log` und `logs\webdav-debug.log` prüfen dort steht, welche Anfrage 4xx/5xx bekommt. 4. **Logs:** `WEBDAV_LOG=debug` in `.env` setzen, Server neu starten, dann `logs\webdav-errors.log` und `logs\webdav-debug.log` prüfen.
## WebDAV-Credentials (für Duplicati, Explorer) ## WebDAV-Credentials (für Duplicati, Explorer)

View File

@@ -26,8 +26,14 @@ if (!token) {
const LOG_DIR = path.join(process.cwd(), 'logs'); const LOG_DIR = path.join(process.cwd(), 'logs');
/** Schreibt in logs/webdav-debug.log (separate Datei, kein Konflikt mit stdout→webdav.log) */ /** WEBDAV_LOG: debug | error | off steuert Datei-Logging (logs/webdav-*.log) */
const WEBDAV_LOG = (process.env.WEBDAV_LOG || '').toLowerCase();
const LOG_DEBUG = WEBDAV_LOG === 'debug' || WEBDAV_LOG === '1';
const LOG_ERROR = LOG_DEBUG || WEBDAV_LOG === 'error';
/** Schreibt in logs/webdav-debug.log (nur bei WEBDAV_LOG=debug) */
function logToFile(...args) { function logToFile(...args) {
if (!LOG_DEBUG) return;
const msg = args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ') + '\n'; const msg = args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ') + '\n';
try { try {
fs.mkdirSync(LOG_DIR, { recursive: true }); fs.mkdirSync(LOG_DIR, { recursive: true });
@@ -35,8 +41,9 @@ function logToFile(...args) {
} catch (_) {} } catch (_) {}
} }
/** Schreibt Fehler in logs/webdav-errors.log (separate Datei, kein Konflikt mit stdout) */ /** Schreibt Fehler in logs/webdav-errors.log (bei WEBDAV_LOG=debug oder error) */
function logError(...args) { function logError(...args) {
if (!LOG_ERROR) return;
const msg = args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ') + '\n'; const msg = args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ') + '\n';
try { try {
fs.mkdirSync(LOG_DIR, { recursive: true }); fs.mkdirSync(LOG_DIR, { recursive: true });
@@ -53,9 +60,6 @@ process.on('uncaughtException', (err) => {
logError('uncaughtException', err.message, err.stack); logError('uncaughtException', err.message, err.stack);
}); });
// Fehlerdatei beim Start anlegen prüft, ob dieser Prozess die neue Version läuft
logError('Server gestartet (Version mit Fehler-Logging)');
/** Cache für neu erstellte Dateien rclone verifiziert per GET direkt nach PUT; API kann verzögert sein */ /** Cache für neu erstellte Dateien rclone verifiziert per GET direkt nach PUT; API kann verzögert sein */
const recentFileCache = new Map(); const recentFileCache = new Map();
const CACHE_TTL_MS = 60_000; const CACHE_TTL_MS = 60_000;
@@ -675,7 +679,7 @@ async function handlePut(req, res) {
if (path.endsWith('/')) path = path.slice(0, -1); if (path.endsWith('/')) path = path.slice(0, -1);
path = sanitizeForPath(path); path = sanitizeForPath(path);
if (process.env.DEBUG) { if (LOG_DEBUG) {
console.log('PUT', path, 'Content-Length:', req.headers['content-length'], 'Body:', req.body?.length ?? 0); console.log('PUT', path, 'Content-Length:', req.headers['content-length'], 'Body:', req.body?.length ?? 0);
} }
@@ -804,9 +808,9 @@ async function handlePut(req, res) {
logError('PUT CATCH', path, err?.message ?? String(err), err?.response?.status, err?.response?.data); logError('PUT CATCH', path, err?.message ?? String(err), err?.response?.status, err?.response?.data);
const apiErr = err.response?.data ? JSON.stringify(err.response.data) : ''; const apiErr = err.response?.data ? JSON.stringify(err.response.data) : '';
const status = err.response?.status; const status = err.response?.status;
if (process.env.DEBUG) logError('Stack:', err.stack); if (LOG_ERROR) logError('Stack:', err.stack);
console.error('PUT Fehler:', path, err.message, status ? `HTTP ${status}` : '', apiErr || ''); console.error('PUT Fehler:', path, err.message, status ? `HTTP ${status}` : '', apiErr || '');
if (process.env.DEBUG) console.error(err.stack); if (LOG_DEBUG) console.error(err.stack);
if (err.message?.includes('Token') || err.response?.status === 401) { if (err.message?.includes('Token') || err.response?.status === 401) {
res.status(401).send('Nicht autorisiert Token erneuern: https://drive.internxt.com'); res.status(401).send('Nicht autorisiert Token erneuern: https://drive.internxt.com');
return; return;