()
| 22 | } |
| 23 | |
| 24 | export function archiveCurrentSession(): void { |
| 25 | const logsDir = getLogsDir() |
| 26 | const hasLogs = LOG_FILES.some(f => existsSync(join(logsDir, f))) |
| 27 | if (!hasLogs) return |
| 28 | |
| 29 | const timestamp = new Date().toISOString().replace(/:/g, '-').slice(0, 19) |
| 30 | const sessionsDir = join(logsDir, 'sessions') |
| 31 | const sessionDir = join(sessionsDir, timestamp) |
| 32 | mkdirSync(sessionDir, { recursive: true }) |
| 33 | |
| 34 | for (const file of LOG_FILES) { |
| 35 | const src = join(logsDir, file) |
| 36 | if (existsSync(src)) { |
| 37 | try { renameSync(src, join(sessionDir, file)) } catch {} |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | // Keep only last MAX_SESSIONS |
| 42 | try { |
| 43 | const sessions = readdirSync(sessionsDir) |
| 44 | .filter(f => statSync(join(sessionsDir, f)).isDirectory()) |
| 45 | .sort() |
| 46 | .reverse() |
| 47 | for (const old of sessions.slice(MAX_SESSIONS)) { |
| 48 | rmSync(join(sessionsDir, old), { recursive: true, force: true }) |
| 49 | } |
| 50 | } catch {} |
| 51 | } |
| 52 | |
| 53 | export const logger = { |
| 54 | info: (msg: string) => { console.log(msg); writeTo('modly.log', line('INFO', msg)) }, |
no test coverage detected