clean up
This commit is contained in:
23
tools/log.js
23
tools/log.js
@@ -1,27 +1,26 @@
|
||||
const fs = require("fs-extra");
|
||||
const dayjs = require("dayjs");
|
||||
const conf = require(`../../conf/townconf.json`);
|
||||
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
|
||||
// in apxtowns/towns/conf/townconf.json .api.activelog a list of context to log
|
||||
// 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.context="apxtri"; // name of model route to find it easily
|
||||
// then l.og(str1,str2,array1,objet,...)
|
||||
//console.log(infos)
|
||||
if (conf.api.activelog.includes(l.context)) {
|
||||
console.log(l.context,'-', ...infos);
|
||||
}
|
||||
|
||||
//console.assert(conf.api.activelog.includes(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}`;
|
||||
const msg = `${days.js().toISOString()}###${l.context}###${tribe}###${info}`;
|
||||
fs.appendFileSync(logf, msg);
|
||||
console.log(msg)
|
||||
};
|
||||
|
Reference in New Issue
Block a user