Files
sashimono/mb-xrpl/lib/logger.js
Ravin Perera 4102c119a4 Automation scripts for Evernode cluster deployment. (#67)
* Message board install automation with faucet host account generation.
* Deregister Evernode host on uninstall.
* Used Evernode client lib in message board.
* Removed file logging by default in Sashimono services.
* Evernode cluster spin-up script.
* Cleaned up hp.cfg template.
2021-10-10 22:21:16 +05:30

40 lines
1.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const util = require('util');
const formatText = (text, logType = 'dbg') => {
const date = new Date().toISOString().
replace(/T/, ' '). // Replace T with a space.
replace(/\..+/, ''). // Delete the dot and everything after.
replace(/-/g, ''); // Delete the dashes.
return `${date} [${logType}] ${text}\n`;
}
exports.init = (logPath, fileLogEnabled) => {
let flog = null;
if (fileLogEnabled) {
const dirname = path.dirname(logPath);
if (!fs.existsSync(dirname))
fs.mkdirSync(dirname, { recursive: true });
flog = fs.createWriteStream(logPath, { flags: 'a' });
}
console.log = function () {
const text = formatText(util.format.apply(this, arguments));
process.stdout.write(text);
if (flog)
flog.write(text);
};
console.error = function () {
const text = formatText(util.format.apply(this, arguments), 'err');
process.stderr.write(text);
if (flog)
flog.write(text);
};
}