1
0
forked from apxtri/apxtri
apxtri/tools/log.js
2024-02-16 08:39:42 +01:00

29 lines
872 B
JavaScript

const fs = require("fs-extra");
const dayjs = require("dayjs");
const conf = require(`../../conf/townconf.json`);
const l = {};
l.context="";
l.og = (...infos) => {
// in apxtowns/towns/conf/townconf.json .api.activelog a list of context to log
// usage:
// const l=require('./tools/log.js');
// 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) => {
const logf = `../../nationchains/tribes/${tribe}/logs/apxtri/apxtri_${tribe}.log`;
const msg = `${days.js().toISOString()}###${l.context}###${tribe}###${info}`;
fs.appendFileSync(logf, msg);
console.log(msg)
};
module.exports = l;