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:
@@ -26,8 +26,14 @@ if (!token) {
|
||||
|
||||
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) {
|
||||
if (!LOG_DEBUG) return;
|
||||
const msg = args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ') + '\n';
|
||||
try {
|
||||
fs.mkdirSync(LOG_DIR, { recursive: true });
|
||||
@@ -35,8 +41,9 @@ function logToFile(...args) {
|
||||
} 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) {
|
||||
if (!LOG_ERROR) return;
|
||||
const msg = args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ') + '\n';
|
||||
try {
|
||||
fs.mkdirSync(LOG_DIR, { recursive: true });
|
||||
@@ -53,9 +60,6 @@ process.on('uncaughtException', (err) => {
|
||||
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 */
|
||||
const recentFileCache = new Map();
|
||||
const CACHE_TTL_MS = 60_000;
|
||||
@@ -675,7 +679,7 @@ async function handlePut(req, res) {
|
||||
if (path.endsWith('/')) path = path.slice(0, -1);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -804,9 +808,9 @@ async function handlePut(req, res) {
|
||||
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 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 || '');
|
||||
if (process.env.DEBUG) console.error(err.stack);
|
||||
if (LOG_DEBUG) console.error(err.stack);
|
||||
if (err.message?.includes('Token') || err.response?.status === 401) {
|
||||
res.status(401).send('Nicht autorisiert – Token erneuern: https://drive.internxt.com');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user