initial commit
This commit is contained in:
commit
8a67761c9a
83 changed files with 15510 additions and 0 deletions
55
lib/logger.ts
Normal file
55
lib/logger.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
// Simple in-memory logger for API requests
|
||||
|
||||
interface LogEntry {
|
||||
timestamp: string;
|
||||
method: string;
|
||||
endpoint: string;
|
||||
statusCode?: number;
|
||||
responseTime?: number;
|
||||
requestBody?: any;
|
||||
error?: string;
|
||||
apiKey?: string; // This will be redacted in the UI
|
||||
}
|
||||
|
||||
class Logger {
|
||||
private logs: LogEntry[] = [];
|
||||
private maxLogs: number = 100;
|
||||
|
||||
log(entry: LogEntry): void {
|
||||
// Remove sensitive information before storing
|
||||
const sanitizedEntry = { ...entry };
|
||||
|
||||
// If apiKey exists, replace it with a redacted version
|
||||
if (sanitizedEntry.apiKey) {
|
||||
const key = sanitizedEntry.apiKey;
|
||||
sanitizedEntry.apiKey = key.substring(0, 4) + '...' + key.substring(key.length - 4);
|
||||
}
|
||||
|
||||
// Add to the beginning for reverse chronological order
|
||||
this.logs.unshift(sanitizedEntry);
|
||||
|
||||
// Trim logs if they exceed the maximum
|
||||
if (this.logs.length > this.maxLogs) {
|
||||
this.logs = this.logs.slice(0, this.maxLogs);
|
||||
}
|
||||
}
|
||||
|
||||
getLogs(): LogEntry[] {
|
||||
// Return a copy of the logs to prevent modification
|
||||
return [...this.logs];
|
||||
}
|
||||
|
||||
clearLogs(): void {
|
||||
this.logs = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Singleton instance
|
||||
let loggerInstance: Logger | null = null;
|
||||
|
||||
export function getLogger(): Logger {
|
||||
if (!loggerInstance) {
|
||||
loggerInstance = new Logger();
|
||||
}
|
||||
return loggerInstance;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue