| 10 | const oldConsoleLog = console.log; |
| 11 | |
| 12 | function findHighestLogNumber(logsDir: string): number { |
| 13 | if (!fs.existsSync(logsDir)) { |
| 14 | return 0; |
| 15 | } |
| 16 | const files = fs.readdirSync(logsDir); |
| 17 | let maxNum = 0; |
| 18 | for (const file of files) { |
| 19 | const match = file.match(/^waveapp\.(\d+)\.log$/); |
| 20 | if (match) { |
| 21 | const num = parseInt(match[1], 10); |
| 22 | if (num > maxNum) { |
| 23 | maxNum = num; |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | return maxNum; |
| 28 | } |
| 29 | |
| 30 | function pruneOldLogs(logsDir: string): { pruned: string[]; error: any } { |
| 31 | if (!fs.existsSync(logsDir)) { |