From 24431c6718b699d489a8dbb089ead79bdf5d10bd Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Wed, 29 Oct 2025 13:15:17 +0100 Subject: [PATCH] feat: add KOMGA_DEBUG environment variable for enhanced logging of Komga requests and responses --- ENV.md | 3 +++ src/lib/services/base-api.service.ts | 38 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/ENV.md b/ENV.md index 140e039..3dbbbd7 100644 --- a/ENV.md +++ b/ENV.md @@ -18,6 +18,9 @@ ADMIN_DEFAULT_PASSWORD=Admin@2025 # Cache Debug (optional - logs cache operations) # CACHE_DEBUG=true +# Komga Debug (optional - logs all requests to Komga) +# KOMGA_DEBUG=true + # Komga Request Queue (optional - max concurrent requests to Komga, default: 2) # KOMGA_MAX_CONCURRENT_REQUESTS=5 diff --git a/src/lib/services/base-api.service.ts b/src/lib/services/base-api.service.ts index ff274c0..4ad76f7 100644 --- a/src/lib/services/base-api.service.ts +++ b/src/lib/services/base-api.service.ts @@ -176,6 +176,19 @@ export abstract class BaseApiService { } } + const isDebug = process.env.KOMGA_DEBUG === 'true'; + const startTime = isDebug ? Date.now() : 0; + + if (isDebug) { + logger.info({ + url, + method: options.method || 'GET', + params, + isImage: options.isImage, + noJson: options.noJson, + }, '🔵 Komga Request'); + } + // Timeout réduit à 15 secondes pour éviter les blocages longs const timeoutMs = 15000; const controller = new AbortController(); @@ -238,7 +251,24 @@ export abstract class BaseApiService { }); clearTimeout(timeoutId); + if (isDebug) { + const duration = Date.now() - startTime; + logger.info({ + url, + status: response.status, + duration: `${duration}ms`, + ok: response.ok, + }, '🟢 Komga Response'); + } + if (!response.ok) { + if (isDebug) { + logger.error({ + url, + status: response.status, + statusText: response.statusText, + }, '🔴 Komga Error Response'); + } throw new AppError(ERROR_CODES.KOMGA.HTTP_ERROR, { status: response.status, statusText: response.statusText, @@ -255,6 +285,14 @@ export abstract class BaseApiService { return response.json(); } catch (error) { + if (isDebug) { + const duration = Date.now() - startTime; + logger.error({ + url, + error: error instanceof Error ? error.message : String(error), + duration: `${duration}ms`, + }, '🔴 Komga Request Failed'); + } throw error; } finally { clearTimeout(timeoutId);