(level: string, component: string, message: string, data?: any)
| 68 | } |
| 69 | |
| 70 | private async write(level: string, component: string, message: string, data?: any) { |
| 71 | if (!this.enabled) return |
| 72 | |
| 73 | try { |
| 74 | await this.ensureLogDir() |
| 75 | |
| 76 | const timestamp = new Date().toISOString() |
| 77 | const dataStr = this.formatData(data) |
| 78 | |
| 79 | const logLine = `${timestamp} ${level.padEnd(5)} ${component}: ${message}${dataStr ? " | " + dataStr : ""}\n` |
| 80 | |
| 81 | const dailyLogDir = join(this.logDir, "daily") |
| 82 | if (!existsSync(dailyLogDir)) { |
| 83 | await mkdir(dailyLogDir, { recursive: true }) |
| 84 | } |
| 85 | |
| 86 | const logFile = join(dailyLogDir, `${new Date().toISOString().split("T")[0]}.log`) |
| 87 | await writeFile(logFile, logLine, { flag: "a" }) |
| 88 | } catch (error) {} |
| 89 | } |
| 90 | |
| 91 | info(message: string, data?: any) { |
| 92 | const component = this.getCallerFile(2) |
no test coverage detected