diff --git a/src/middleware/loggingMiddleware.ts b/src/middleware/loggingMiddleware.ts index 761f1ac6..532bfe6d 100644 --- a/src/middleware/loggingMiddleware.ts +++ b/src/middleware/loggingMiddleware.ts @@ -3,11 +3,9 @@ import { NextRequest, NextResponse } from 'next/server'; const LOG_LEVELS = ["debug", "info", "warn", "error"] as const; type LogLevel = typeof LOG_LEVELS[number]; -function currentLevelIndex(): number { - const raw = (process.env.LOG_LEVEL ?? "info") as LogLevel; - const idx = LOG_LEVELS.indexOf(raw); - return idx === -1 ? 1 : idx; -} +const raw = (process.env.LOG_LEVEL ?? "info") as LogLevel; +const _idx = LOG_LEVELS.indexOf(raw); +const LEVEL_INDEX = _idx === -1 ? 1 : _idx; const STATUS_PATH_RE = /\/api\/agent\/[^/]+\/status\/?$/; @@ -16,7 +14,7 @@ export function loggingMiddleware(request: NextRequest) { const isStatusPing = STATUS_PATH_RE.test(request.nextUrl.pathname); // Status pings are debug-level; all other API calls are info-level. const requiredIndex = isStatusPing ? 0 : 1; - if (currentLevelIndex() <= requiredIndex) { + if (LEVEL_INDEX <= requiredIndex) { console.log(`[API] Received ${request.method} request : ${request.url} at ${new Date()}`); } }