36 lines
1002 B
JavaScript
36 lines
1002 B
JavaScript
const fs = require("fs");
|
|
const moment = require("moment");
|
|
|
|
const addLogFunction = async (fileName, data, functionName) => {
|
|
try {
|
|
fs.exists(fileName, async (exists) => {
|
|
if (exists) {
|
|
let old_data = await fs.readFileSync(fileName, "utf8");
|
|
fs.writeFileSync(
|
|
fileName,
|
|
old_data +
|
|
"\n\n[" +
|
|
moment(Date.now()).format("D/M/YY-HH:mm:ss") +
|
|
"] - " +
|
|
functionName +
|
|
"\n" +
|
|
data +
|
|
"\n\n======================================================================"
|
|
);
|
|
} else {
|
|
fs.writeFileSync(
|
|
fileName,
|
|
"\n\n[" +
|
|
moment(Date.now()).format("D/M/YY-HH:mm:ss") +
|
|
"] - System Logs" +
|
|
data +
|
|
"\n\n======================================================================"
|
|
);
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
};
|
|
|
|
module.exports.addLogFunction = addLogFunction; |