Implement centralized logging with RMABLogger

Replaces scattered console statements with a unified RMABLogger across backend API routes and services. Adds LOG_LEVEL-based filtering, job-aware database persistence, and context-based logging. Updates documentation to describe the new logging system and usage patterns. Also documents qBittorrent CSRF header fix
This commit is contained in:
kikootwo
2026-01-12 12:45:48 -05:00
parent ba5f5cf7d6
commit 682836237b
118 changed files with 1623 additions and 1079 deletions
+6 -3
View File
@@ -9,6 +9,9 @@ import { prisma } from '@/lib/db';
import { getJobQueueService } from '@/lib/services/job-queue.service';
import { findPlexMatch } from '@/lib/utils/audiobook-matcher';
import { z } from 'zod';
import { RMABLogger } from '@/lib/utils/logger';
const logger = RMABLogger.create('API.Requests');
const CreateRequestSchema = z.object({
audiobook: z.object({
@@ -138,7 +141,7 @@ export async function POST(request: NextRequest) {
}
// Delete the existing failed/warn/cancelled request
console.log(`[Requests] Deleting existing ${existingRequest.status} request ${existingRequest.id} to allow re-request`);
logger.debug(`Deleting existing ${existingRequest.status} request ${existingRequest.id} to allow re-request`);
await prisma.request.delete({
where: { id: existingRequest.id },
});
@@ -181,7 +184,7 @@ export async function POST(request: NextRequest) {
request: newRequest,
}, { status: 201 });
} catch (error) {
console.error('Failed to create request:', error);
logger.error('Failed to create request', { error: error instanceof Error ? error.message : String(error) });
if (error instanceof z.ZodError) {
return NextResponse.json(
@@ -255,7 +258,7 @@ export async function GET(request: NextRequest) {
count: requests.length,
});
} catch (error) {
console.error('Failed to get requests:', error);
logger.error('Failed to get requests', { error: error instanceof Error ? error.message : String(error) });
return NextResponse.json(
{
error: 'FetchError',