feature/Reynolds-and-Reynolds-DMS-API-Integration -Expand
This commit is contained in:
@@ -1,8 +1,49 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// Thin wrapper around the shared logger + a socket emitter,
|
||||
// mirroring the Fortellis logger shape for parity.
|
||||
//
|
||||
// Emits: "rr-log-event" { level, message, txnDetails }
|
||||
//
|
||||
// NOTE: Keep this lightweight and side-effect free—downstream flows rely on it
|
||||
// for both developer troubleshooting and UI progress messages.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const CreateRRLogEvent = (socket, level, message, txnDetails) => {
|
||||
logger.log("rr-log-event", level, socket?.user?.email, null, { wsmessage: message, txnDetails });
|
||||
socket.emit("rr-log-event", { level, message, txnDetails });
|
||||
};
|
||||
/**
|
||||
* Emit a structured RR log event to both the central logger and (if present)
|
||||
* over the current socket connection for real-time UI visibility.
|
||||
*
|
||||
* @param {Object} socket - A Socket.IO socket OR an Express req (when reused in REST).
|
||||
* Expected fields if present:
|
||||
* - socket.user?.email (used as the "actor" for audit trails)
|
||||
* - socket.emit(...) method in live socket contexts
|
||||
* @param {"SILLY"|"DEBUG"|"INFO"|"WARN"|"ERROR"} level - Log severity
|
||||
* @param {string} message - Human readable message
|
||||
* @param {Object} [txnDetails] - Optional structured metadata (ids, payload snippets, timings)
|
||||
*/
|
||||
function CreateRRLogEvent(socket, level, message, txnDetails) {
|
||||
const userEmail = socket?.user?.email || "unknown";
|
||||
|
||||
// 1) Centralized app logger (goes to your sinks: console, Datadog, etc.)
|
||||
// Namespace: "rr-log-event" to keep provider logs grouped.
|
||||
try {
|
||||
logger.log("rr-log-event", level, userEmail, null, {
|
||||
wsmessage: message,
|
||||
txnDetails
|
||||
});
|
||||
} catch {
|
||||
// Best-effort: never throw from logging
|
||||
}
|
||||
|
||||
// 2) Realtime push to the UI if we're in a socket context
|
||||
try {
|
||||
if (typeof socket?.emit === "function") {
|
||||
socket.emit("rr-log-event", { level, message, txnDetails });
|
||||
}
|
||||
} catch {
|
||||
// Best-effort: never throw from logging
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CreateRRLogEvent;
|
||||
|
||||
Reference in New Issue
Block a user