forked from apxtri/apxtri
30 lines
899 B
JavaScript
30 lines
899 B
JavaScript
const fs = require("fs-extra");
|
|
const dayjs = require("dayjs");
|
|
const l = {};
|
|
l.context="";
|
|
l.showlog=(process.env.NODE_MODE=="dev");
|
|
l.og = (...infos) => {
|
|
// by default if NODE_MODE is dev => l.showlog at true
|
|
// if l.showlog is set to false then it does not output log
|
|
// l.context is a prefixe to help understanding
|
|
// usage:
|
|
// const l=require('./tools/log.js');
|
|
// l.showlog= true; // force log as well in prod and dev
|
|
// l.context="apxtri";
|
|
// l.og(stringify)
|
|
|
|
if (l.showlog) {
|
|
console.log(l.context,'-', infos);
|
|
}
|
|
};
|
|
|
|
l.ogprod = (tribe,info) => {
|
|
//store log in file /nationchains/tribes/{tribe}/logs/apxtri/apxtri_{tribe}.log
|
|
const logf = `../../nationchains/tribes/${tribe}/logs/apxtri/apxtri_${tribe}.log`;
|
|
const msg = `${days.js().toISOString()}###${tribe}###${info}`;
|
|
fs.appendFileSync(logf, msg);
|
|
console.log(msg)
|
|
};
|
|
|
|
module.exports = l;
|