mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: suppress agent status ping logs below debug level
This commit is contained in:
@@ -1,8 +1,24 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
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 STATUS_PATH_RE = /\/api\/agent\/[^/]+\/status\/?$/;
|
||||||
|
|
||||||
export function loggingMiddleware(request: NextRequest) {
|
export function loggingMiddleware(request: NextRequest) {
|
||||||
if (request.url.includes('/api')) {
|
if (request.url.includes('/api')) {
|
||||||
|
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) {
|
||||||
console.log(`[API] Received ${request.method} request : ${request.url} at ${new Date()}`);
|
console.log(`[API] Received ${request.method} request : ${request.url} at ${new Date()}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user