diff --git a/index.js b/index.js index 7b7e719..9fe21d5 100644 --- a/index.js +++ b/index.js @@ -457,30 +457,31 @@ xmpp.on("stanza", (stanza) => { const bodyData = getFirstURL(body); // get product id from "x" tag var evt = events[product_id.pil.substring(0, 3)]; - - // Log the full event object to a file named "productid-timestamp-channelname.json" - const nowDate = new Date(); - const year = nowDate.getFullYear(); - const month = String(nowDate.getMonth() + 1).padStart(2, '0'); - const day = String(nowDate.getDate()).padStart(2, '0'); - const logDir = path.join(__dirname, "event-logs", year.toString(), month, day); - if (!fs.existsSync(logDir)) { - fs.mkdirSync(logDir, { recursive: true }); - } - const logFilename = `${product_id_raw}-${product_id.timestamp.toISOString()}-${fromChannel}.json`.replace(/[:]/g, "_"); - const logPath = path.join(logDir, logFilename); - const getCircularReplacer = () => { - const seen = new WeakSet(); - return (key, value) => { - if (typeof value === "object" && value !== null) { - if (seen.has(value)) { - return "WARN: CIRC"; + if (process.env.LOG_EVENTS === "true") { + // Log the full event object to a file named "productid-timestamp-channelname.json" + const nowDate = new Date(); + const year = nowDate.getFullYear(); + const month = String(nowDate.getMonth() + 1).padStart(2, '0'); + const day = String(nowDate.getDate()).padStart(2, '0'); + const logDir = path.join(__dirname, "event-logs", year.toString(), month, day); + if (!fs.existsSync(logDir)) { + fs.mkdirSync(logDir, { recursive: true }); + } + const logFilename = `${product_id_raw}-${product_id.timestamp.toISOString()}-${fromChannel}.json`.replace(/[:]/g, "_"); + const logPath = path.join(logDir, logFilename); + const getCircularReplacer = () => { + const seen = new WeakSet(); + return (key, value) => { + if (typeof value === "object" && value !== null) { + if (seen.has(value)) { + return "WARN: CIRC"; + } + seen.add(value); } - seen.add(value); - } - return value; + return value; + }; }; - }; + } if (!evt) { evt = { name: "Unknown", priority: 3 }