| 61 | |
| 62 | // Logger decorator to add persistent storage |
| 63 | class PersistentLogger implements Logger { |
| 64 | constructor( |
| 65 | private baseLogger: Logger, |
| 66 | private storageService: StorageService, |
| 67 | ) {} |
| 68 | |
| 69 | log(message: string, level: LogLevel = "info"): void { |
| 70 | // First use the base logger |
| 71 | this.baseLogger.log(message, level); |
| 72 | |
| 73 | // Then persist the log |
| 74 | const timestamp = new Date().toISOString(); |
| 75 | try { |
| 76 | const logs = JSON.parse( |
| 77 | this.storageService.getItem("system_logs") || "[]", |
| 78 | ); |
| 79 | logs.push({ timestamp, level, message }); |
| 80 | this.storageService.setItem("system_logs", JSON.stringify(logs)); |
| 81 | } catch (e) { |
| 82 | this.baseLogger.log("Failed to persist log", "error"); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Notification service - Single Responsibility |
| 88 | class NotificationService { |
nothing calls this directly
no outgoing calls
no test coverage detected