God these logs are gonna be the END OF ME
This commit is contained in:
parent
0e64a9f0c8
commit
0752221b85
45
index.js
45
index.js
|
|
@ -457,30 +457,31 @@ xmpp.on("stanza", (stanza) => {
|
||||||
const bodyData = getFirstURL(body);
|
const bodyData = getFirstURL(body);
|
||||||
// get product id from "x" tag
|
// get product id from "x" tag
|
||||||
var evt = events[product_id.pil.substring(0, 3)];
|
var evt = events[product_id.pil.substring(0, 3)];
|
||||||
|
if (process.env.LOG_EVENTS === "true") {
|
||||||
// Log the full event object to a file named "productid-timestamp-channelname.json"
|
// Log the full event object to a file named "productid-timestamp-channelname.json"
|
||||||
const nowDate = new Date();
|
const nowDate = new Date();
|
||||||
const year = nowDate.getFullYear();
|
const year = nowDate.getFullYear();
|
||||||
const month = String(nowDate.getMonth() + 1).padStart(2, '0');
|
const month = String(nowDate.getMonth() + 1).padStart(2, '0');
|
||||||
const day = String(nowDate.getDate()).padStart(2, '0');
|
const day = String(nowDate.getDate()).padStart(2, '0');
|
||||||
const logDir = path.join(__dirname, "event-logs", year.toString(), month, day);
|
const logDir = path.join(__dirname, "event-logs", year.toString(), month, day);
|
||||||
if (!fs.existsSync(logDir)) {
|
if (!fs.existsSync(logDir)) {
|
||||||
fs.mkdirSync(logDir, { recursive: true });
|
fs.mkdirSync(logDir, { recursive: true });
|
||||||
}
|
}
|
||||||
const logFilename = `${product_id_raw}-${product_id.timestamp.toISOString()}-${fromChannel}.json`.replace(/[:]/g, "_");
|
const logFilename = `${product_id_raw}-${product_id.timestamp.toISOString()}-${fromChannel}.json`.replace(/[:]/g, "_");
|
||||||
const logPath = path.join(logDir, logFilename);
|
const logPath = path.join(logDir, logFilename);
|
||||||
const getCircularReplacer = () => {
|
const getCircularReplacer = () => {
|
||||||
const seen = new WeakSet();
|
const seen = new WeakSet();
|
||||||
return (key, value) => {
|
return (key, value) => {
|
||||||
if (typeof value === "object" && value !== null) {
|
if (typeof value === "object" && value !== null) {
|
||||||
if (seen.has(value)) {
|
if (seen.has(value)) {
|
||||||
return "WARN: CIRC";
|
return "WARN: CIRC";
|
||||||
|
}
|
||||||
|
seen.add(value);
|
||||||
}
|
}
|
||||||
seen.add(value);
|
return value;
|
||||||
}
|
};
|
||||||
return value;
|
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
if (!evt) {
|
if (!evt) {
|
||||||
evt = { name: "Unknown", priority: 3 }
|
evt = { name: "Unknown", priority: 3 }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue