- P2-1: Consolidate mock ML logic to Python canonical source - P2-2: Fix weak hashes with SHA-256 - P2-3: Parallelize batch processing with Promise.allSettled() - P2-4: Add DI pattern support to services - P2-5: Add structured logging utility - P3-2: Persist batch jobId for result retrieval Co-Authored-By: Paperclip <noreply@paperclip.ing>
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { FastifyLoggerOptions } from 'fastify';
|
|
|
|
export interface Logger {
|
|
info(message: string, context?: Record<string, unknown>): void;
|
|
warn(message: string, context?: Record<string, unknown>): void;
|
|
error(message: string, context?: Record<string, unknown>): void;
|
|
debug(message: string, context?: Record<string, unknown>): void;
|
|
}
|
|
|
|
export class ConsoleLogger implements Logger {
|
|
info(message: string, context?: Record<string, unknown>): void {
|
|
const timestamp = new Date().toISOString();
|
|
const logContext = context ? ` ${JSON.stringify(context)}` : '';
|
|
console.log(`[${timestamp}] [INFO] ${message}${logContext}`);
|
|
}
|
|
|
|
warn(message: string, context?: Record<string, unknown>): void {
|
|
const timestamp = new Date().toISOString();
|
|
const logContext = context ? ` ${JSON.stringify(context)}` : '';
|
|
console.warn(`[${timestamp}] [WARN] ${message}${logContext}`);
|
|
}
|
|
|
|
error(message: string, context?: Record<string, unknown>): void {
|
|
const timestamp = new Date().toISOString();
|
|
const logContext = context ? ` ${JSON.stringify(context)}` : '';
|
|
console.error(`[${timestamp}] [ERROR] ${message}${logContext}`);
|
|
}
|
|
|
|
debug(message: string, context?: Record<string, unknown>): void {
|
|
const timestamp = new Date().toISOString();
|
|
const logContext = context ? ` ${JSON.stringify(context)}` : '';
|
|
console.debug(`[${timestamp}] [DEBUG] ${message}${logContext}`);
|
|
}
|
|
}
|
|
|
|
export const logger = new ConsoleLogger();
|