Files

35 lines
711 B
TypeScript

import { ApiService } from '../services/api';
class Logger {
private logs: string[] = [];
private maxLogs = 50;
log(message: string, type: 'info' | 'error' | 'sync' | 'success' = 'info') {
const timestamp = new Date().toLocaleTimeString();
const entry = `[${timestamp}] [${type.toUpperCase()}] ${message}`;
this.logs.unshift(entry);
if (this.logs.length > this.maxLogs) {
this.logs.pop();
}
if (type === 'error') {
ApiService.reportError(message, 'error').catch(() => {});
}
if (__DEV__) {
console.log(entry);
}
}
getLogs() {
return this.logs;
}
clear() {
this.logs = [];
}
}
export const DebugLogger = new Logger();