• Archive the current log file with a timestamp Used during application startup to start with a clean log

    Parameters

    • maxLogFiles: number = 10

      Optional parameter for maximum log files to keep (defaults to 10)

    Returns void

    export function archiveCurrentLog(maxLogFiles = 10): void {
    const latestLogPath = path.join(logsPath, "latest.log");

    if (fs.existsSync(latestLogPath)) {
    try {
    const stats = fs.statSync(latestLogPath);
    const logDate = new Date(stats.mtime);
    const timestamp = logDate.toISOString().replace(/[:.]/g, "-");
    const archivedLogPath = path.join(
    logsPath,
    `spotify-skip-tracker-${timestamp}.log`,
    );
    fs.renameSync(latestLogPath, archivedLogPath);
    console.log(`Archived previous log to ${archivedLogPath}`);

    // Clean up old logs after archiving
    cleanupOldLogs(maxLogFiles);
    } catch (error) {
    console.error("Failed to archive previous log:", error);
    }
    }
    }