32 lines
934 B
JavaScript
32 lines
934 B
JavaScript
const fs = require('fs');
|
|
const moment = require('moment');
|
|
const config = require('config');
|
|
|
|
let current_error_count = 0;
|
|
let max_fails = config.settings.max_fails;
|
|
|
|
module.exports.writeLog = async (value) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
await fs.writeFile('./logs/simulator.log', `[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${value}\n`, {'flag':'a'}, (err) => {
|
|
if (err) { reject(err); }
|
|
else { resolve(); }
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports.writeErrorLog = async (value) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
current_error_count++;
|
|
console.log(`ERROR: ${value} ${current_error_count}`);
|
|
|
|
await fs.writeFile('./logs/error.log', `[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${value} [${current_error_count}]\n`, {'flag':'a'}, (err) => {
|
|
if (err) { reject(err); }
|
|
else {
|
|
if(current_error_count >= max_fails) {
|
|
process.exit(0);
|
|
}
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
} |