const fs = require('fs');
const path = require('path');
function appendToLogFile(tableName, id, change) {
    const log = {
        timestamp: new Date().toISOString(),
        id: id,
        change: change
    };


    var logFileName = `../applogs/log_${tableName}_${log.timestamp.slice(0, 10)}.txt`; // Generate file name with date
    logFileName = path.join(__dirname, logFileName);
    if (!fs.existsSync(logFileName)) {
        fs.writeFileSync(logFileName, ''); // Create the file if it doesn't exist
    }

    fs.appendFile(logFileName, `\n${log.timestamp} ${log.id} ${log.change}`, (err) => {
        if (err) throw err;
        console.log(`Data appended to ${logFileName}`);
    });
}


module.exports = appendToLogFile;