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);
|
||||
// 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 }
|
||||
|
|
|
|||
Loading…
Reference in a new issue