Merged in release/2024-11-01 (pull request #1853)
Release/2024-11-01 into master-AIO - Fix Logging Issues
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
client_max_body_size 50M;
|
client_max_body_size 50M;
|
||||||
|
client_body_buffer_size 5M;
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ export function DmsLogEvents({ socket, logs, bodyshop }) {
|
|||||||
|
|
||||||
function LogLevelHierarchy(level) {
|
function LogLevelHierarchy(level) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case "TRACE":
|
|
||||||
return "pink";
|
|
||||||
case "DEBUG":
|
case "DEBUG":
|
||||||
return "orange";
|
return "orange";
|
||||||
case "INFO":
|
case "INFO":
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
|||||||
socket.emit("set-log-level", value);
|
socket.emit("set-log-level", value);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Select.Option key="TRACE">TRACE</Select.Option>
|
|
||||||
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
||||||
<Select.Option key="INFO">INFO</Select.Option>
|
<Select.Option key="INFO">INFO</Select.Option>
|
||||||
<Select.Option key="WARNING">WARNING</Select.Option>
|
<Select.Option key="WARNING">WARNING</Select.Option>
|
||||||
|
|||||||
@@ -173,7 +173,6 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
socket.emit("set-log-level", value);
|
socket.emit("set-log-level", value);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Select.Option key="TRACE">TRACE</Select.Option>
|
|
||||||
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
<Select.Option key="DEBUG">DEBUG</Select.Option>
|
||||||
<Select.Option key="INFO">INFO</Select.Option>
|
<Select.Option key="INFO">INFO</Select.Option>
|
||||||
<Select.Option key="WARNING">WARNING</Select.Option>
|
<Select.Option key="WARNING">WARNING</Select.Option>
|
||||||
|
|||||||
28
server.js
28
server.js
@@ -153,18 +153,13 @@ const connectToRedisCluster = async () => {
|
|||||||
} else {
|
} else {
|
||||||
// Use the Dockerized Redis cluster in development
|
// Use the Dockerized Redis cluster in development
|
||||||
if (isEmpty(process.env?.REDIS_URL) || !isString(process.env?.REDIS_URL)) {
|
if (isEmpty(process.env?.REDIS_URL) || !isString(process.env?.REDIS_URL)) {
|
||||||
logger.log(`[${process.env.NODE_ENV}] No or Malformed REDIS_URL present.`, "ERROR", "redis", "api");
|
logger.log(`No or Malformed REDIS_URL present.`, "ERROR", "redis", "api");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
redisServers = JSON.parse(process.env.REDIS_URL);
|
redisServers = JSON.parse(process.env.REDIS_URL);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log(
|
logger.log(`Failed to parse REDIS_URL: ${error.message}. Exiting...`, "ERROR", "redis", "api");
|
||||||
`[${process.env.NODE_ENV}] Failed to parse REDIS_URL: ${error.message}. Exiting...`,
|
|
||||||
"ERROR",
|
|
||||||
"redis",
|
|
||||||
"api"
|
|
||||||
);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,12 +167,7 @@ const connectToRedisCluster = async () => {
|
|||||||
const clusterRetryStrategy = (times) => {
|
const clusterRetryStrategy = (times) => {
|
||||||
const delay =
|
const delay =
|
||||||
Math.min(CLUSTER_RETRY_BASE_DELAY + times * 50, CLUSTER_RETRY_MAX_DELAY) + Math.random() * CLUSTER_RETRY_JITTER;
|
Math.min(CLUSTER_RETRY_BASE_DELAY + times * 50, CLUSTER_RETRY_MAX_DELAY) + Math.random() * CLUSTER_RETRY_JITTER;
|
||||||
logger.log(
|
logger.log(`Redis cluster not yet ready. Retrying in ${delay.toFixed(2)}ms`, "WARN", "redis", "api");
|
||||||
`[${process.env.NODE_ENV}] Redis cluster not yet ready. Retrying in ${delay.toFixed(2)}ms`,
|
|
||||||
"WARN",
|
|
||||||
"redis",
|
|
||||||
"api"
|
|
||||||
);
|
|
||||||
return delay;
|
return delay;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -194,12 +184,12 @@ const connectToRedisCluster = async () => {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
redisCluster.on("ready", () => {
|
redisCluster.on("ready", () => {
|
||||||
logger.log(`[${process.env.NODE_ENV}] Redis cluster connection established.`, "INFO", "redis", "api");
|
logger.log(`Redis cluster connection established.`, "INFO", "redis", "api");
|
||||||
resolve(redisCluster);
|
resolve(redisCluster);
|
||||||
});
|
});
|
||||||
|
|
||||||
redisCluster.on("error", (err) => {
|
redisCluster.on("error", (err) => {
|
||||||
logger.log(`[${process.env.NODE_ENV}] Redis cluster connection failed: ${err.message}`, "ERROR", "redis", "api");
|
logger.log(`Redis cluster connection failed: ${err.message}`, "ERROR", "redis", "api");
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -215,7 +205,7 @@ const applySocketIO = async ({ server, app }) => {
|
|||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
redisCluster.on("error", (err) => {
|
redisCluster.on("error", (err) => {
|
||||||
logger.log(`[${process.env.NODE_ENV}] Redis ERROR`, "ERROR", "redis", "api");
|
logger.log(`Redis ERROR`, "ERROR", "redis", "api");
|
||||||
});
|
});
|
||||||
|
|
||||||
const pubClient = redisCluster;
|
const pubClient = redisCluster;
|
||||||
@@ -249,7 +239,7 @@ const applySocketIO = async ({ server, app }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isString(process.env.REDIS_ADMIN_PASS) && !isEmpty(process.env.REDIS_ADMIN_PASS)) {
|
if (isString(process.env.REDIS_ADMIN_PASS) && !isEmpty(process.env.REDIS_ADMIN_PASS)) {
|
||||||
logger.log(`[${process.env.NODE_ENV}] Initializing Redis Admin UI....`, "INFO", "redis", "api");
|
logger.log(`Initializing Redis Admin UI....`, "INFO", "redis", "api");
|
||||||
instrument(ioRedis, {
|
instrument(ioRedis, {
|
||||||
auth: {
|
auth: {
|
||||||
type: "basic",
|
type: "basic",
|
||||||
@@ -312,9 +302,9 @@ const main = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await server.listen(port);
|
await server.listen(port);
|
||||||
logger.log(`[${process.env.NODE_ENV}] Server started on port ${port}`, "INFO", "api");
|
logger.log(`Server started on port ${port}`, "INFO", "api");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log(`[${process.env.NODE_ENV}] Server failed to start on port ${port}`, "ERROR", "api", error);
|
logger.log(`Server failed to start on port ${port}`, "ERROR", "api", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ axios.interceptors.request.use((x) => {
|
|||||||
} | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`;
|
} | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`;
|
||||||
//console.log(printable);
|
//console.log(printable);
|
||||||
|
|
||||||
CdkBase.createJsonEvent(socket, "TRACE", `Raw Request: ${printable}`, x.data);
|
CdkBase.createJsonEvent(socket, "SILLY", `Raw Request: ${printable}`, x.data);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
@@ -36,7 +36,7 @@ axios.interceptors.response.use((x) => {
|
|||||||
|
|
||||||
const printable = `${new Date()} | Response: ${x.status} | ${JSON.stringify(x.data)}`;
|
const printable = `${new Date()} | Response: ${x.status} | ${JSON.stringify(x.data)}`;
|
||||||
//console.log(printable);
|
//console.log(printable);
|
||||||
CdkBase.createJsonEvent(socket, "TRACE", `Raw Response: ${printable}`, x.data);
|
CdkBase.createJsonEvent(socket, "SILLY", `Raw Response: ${printable}`, x.data);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
@@ -181,7 +181,7 @@ async function QueryBillData(socket, billids) {
|
|||||||
const result = await client
|
const result = await client
|
||||||
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
||||||
.request(queries.GET_PBS_AP_ALLOCATIONS, { billids: billids });
|
.request(queries.GET_PBS_AP_ALLOCATIONS, { billids: billids });
|
||||||
CdkBase.createLogEvent(socket, "TRACE", `Bill data query result ${JSON.stringify(result, null, 2)}`);
|
CdkBase.createLogEvent(socket, "SILLY", `Bill data query result ${JSON.stringify(result, null, 2)}`);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ axios.interceptors.request.use((x) => {
|
|||||||
} | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`;
|
} | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`;
|
||||||
//console.log(printable);
|
//console.log(printable);
|
||||||
|
|
||||||
CdkBase.createJsonEvent(socket, "TRACE", `Raw Request: ${printable}`, x.data);
|
CdkBase.createJsonEvent(socket, "SILLY", `Raw Request: ${printable}`, x.data);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
@@ -38,7 +38,7 @@ axios.interceptors.response.use((x) => {
|
|||||||
|
|
||||||
const printable = `${new Date()} | Response: ${x.status} | ${JSON.stringify(x.data)}`;
|
const printable = `${new Date()} | Response: ${x.status} | ${JSON.stringify(x.data)}`;
|
||||||
//console.log(printable);
|
//console.log(printable);
|
||||||
CdkBase.createJsonEvent(socket, "TRACE", `Raw Response: ${printable}`, x.data);
|
CdkBase.createJsonEvent(socket, "SILLY", `Raw Response: ${printable}`, x.data);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
@@ -118,7 +118,7 @@ async function CheckForErrors(socket, response) {
|
|||||||
CdkBase.createLogEvent(socket, "DEBUG", `Successful response from DMS. ${response.Message || ""}`);
|
CdkBase.createLogEvent(socket, "DEBUG", `Successful response from DMS. ${response.Message || ""}`);
|
||||||
} else {
|
} else {
|
||||||
CdkBase.createLogEvent(socket, "ERROR", `Error received from DMS: ${response.Message}`);
|
CdkBase.createLogEvent(socket, "ERROR", `Error received from DMS: ${response.Message}`);
|
||||||
CdkBase.createLogEvent(socket, "TRACE", `Error received from DMS: ${JSON.stringify(response)}`);
|
CdkBase.createLogEvent(socket, "SILLY", `Error received from DMS: ${JSON.stringify(response)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ async function QueryJobData(socket, jobid) {
|
|||||||
const result = await client
|
const result = await client
|
||||||
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
||||||
.request(queries.QUERY_JOBS_FOR_PBS_EXPORT, { id: jobid });
|
.request(queries.QUERY_JOBS_FOR_PBS_EXPORT, { id: jobid });
|
||||||
CdkBase.createLogEvent(socket, "TRACE", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
CdkBase.createLogEvent(socket, "SILLY", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
||||||
return result.jobs_by_pk;
|
return result.jobs_by_pk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ async function QueryJobData(connectionData, token, jobid) {
|
|||||||
CdkBase.createLogEvent(connectionData, "DEBUG", `Querying job data for id ${jobid}`);
|
CdkBase.createLogEvent(connectionData, "DEBUG", `Querying job data for id ${jobid}`);
|
||||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
||||||
const result = await client.setHeaders({ Authorization: token }).request(queries.GET_CDK_ALLOCATIONS, { id: jobid });
|
const result = await client.setHeaders({ Authorization: token }).request(queries.GET_CDK_ALLOCATIONS, { id: jobid });
|
||||||
CdkBase.createLogEvent(connectionData, "TRACE", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
CdkBase.createLogEvent(connectionData, "SILLY", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
||||||
return result.jobs_by_pk;
|
return result.jobs_by_pk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,13 +373,19 @@ function calculateAllocations(connectionData, job) {
|
|||||||
});
|
});
|
||||||
//profile level adjustments for labor and materials
|
//profile level adjustments for labor and materials
|
||||||
Object.keys(job.job_totals.rates).forEach((key) => {
|
Object.keys(job.job_totals.rates).forEach((key) => {
|
||||||
if (job.job_totals.rates[key] && job.job_totals.rates[key].adjustment && Dinero(job.job_totals.rates[key].adjustment).isZero() === false) {
|
if (
|
||||||
|
job.job_totals.rates[key] &&
|
||||||
|
job.job_totals.rates[key].adjustment &&
|
||||||
|
Dinero(job.job_totals.rates[key].adjustment).isZero() === false
|
||||||
|
) {
|
||||||
const accountName = selectedDmsAllocationConfig.profits[key.toUpperCase()];
|
const accountName = selectedDmsAllocationConfig.profits[key.toUpperCase()];
|
||||||
const otherAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === accountName);
|
const otherAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === accountName);
|
||||||
if (otherAccount) {
|
if (otherAccount) {
|
||||||
if (!profitCenterHash[accountName]) profitCenterHash[accountName] = Dinero();
|
if (!profitCenterHash[accountName]) profitCenterHash[accountName] = Dinero();
|
||||||
|
|
||||||
profitCenterHash[accountName] = profitCenterHash[accountName].add(Dinero(job.job_totals.rates[key].adjustments));
|
profitCenterHash[accountName] = profitCenterHash[accountName].add(
|
||||||
|
Dinero(job.job_totals.rates[key].adjustments)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
connectionData,
|
connectionData,
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ async function QueryJobData(socket, jobid) {
|
|||||||
const result = await client
|
const result = await client
|
||||||
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
.setHeaders({ Authorization: `Bearer ${socket.handshake.auth.token}` })
|
||||||
.request(queries.QUERY_JOBS_FOR_CDK_EXPORT, { id: jobid });
|
.request(queries.QUERY_JOBS_FOR_CDK_EXPORT, { id: jobid });
|
||||||
CdkBase.createLogEvent(socket, "TRACE", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
CdkBase.createLogEvent(socket, "SILLY", `Job data query result ${JSON.stringify(result, null, 2)}`);
|
||||||
return result.jobs_by_pk;
|
return result.jobs_by_pk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ async function CalculateDmsVid(socket, JobData) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientVehicleInsertUpdate.getVehIdsAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientVehicleInsertUpdate.getVehIdsAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
||||||
@@ -214,7 +214,7 @@ async function QueryDmsVehicleById(socket, JobData, DMSVid) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientVehicleInsertUpdate.readAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientVehicleInsertUpdate.readAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.readAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.readAsync response.`);
|
||||||
@@ -246,7 +246,7 @@ async function QueryDmsCustomerById(socket, JobData, CustomerId) {
|
|||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientCustomerInsertUpdate.readAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientCustomerInsertUpdate.readAsync response.`);
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientCustomerInsertUpdate.readAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientCustomerInsertUpdate.readAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||||
@@ -295,7 +295,7 @@ async function QueryDmsCustomerByName(socket, JobData) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientCustomerSearch.executeSearchBulkAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientCustomerSearch.executeSearchBulkAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CheckCdkResponseForError(socket, soapResponseCustomerSearch);
|
CheckCdkResponseForError(socket, soapResponseCustomerSearch);
|
||||||
@@ -337,7 +337,7 @@ async function GenerateDmsCustomerNumber(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientCustomerInsertUpdate.getCustomerNumberAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientCustomerInsertUpdate.getCustomerNumberAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||||
@@ -425,7 +425,7 @@ async function InsertDmsCustomer(socket, newCustomerNumber) {
|
|||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientCustomerInsertUpdate.insertAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientCustomerInsertUpdate.insertAsync response.`);
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientCustomerInsertUpdate.insertAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientCustomerInsertUpdate.insertAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||||
@@ -505,7 +505,7 @@ async function InsertDmsVehicle(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientVehicleInsertUpdate.insertAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientVehicleInsertUpdate.insertAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.insertAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.insertAsync response.`);
|
||||||
@@ -611,7 +611,7 @@ async function UpdateDmsVehicle(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"DEBUG",
|
||||||
`soapClientVehicleInsertUpdate.updateAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientVehicleInsertUpdate.updateAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.updateAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.updateAsync response.`);
|
||||||
@@ -650,7 +650,7 @@ async function InsertServiceVehicleHistory(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientServiceHistoryInsert.serviceHistoryHeaderInsert Result ${JSON.stringify(result, null, 2)}`
|
`soapClientServiceHistoryInsert.serviceHistoryHeaderInsert Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientServiceHistoryInsert.serviceHistoryHeaderInsert response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientServiceHistoryInsert.serviceHistoryHeaderInsert response.`);
|
||||||
@@ -690,7 +690,7 @@ async function InsertDmsStartWip(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientAccountingGLInsertUpdate.doStartWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientAccountingGLInsertUpdate.doStartWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doStartWIPAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doStartWIPAsync response.`);
|
||||||
@@ -721,7 +721,7 @@ async function InsertDmsBatchWip(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doTransBatchWIPAsync response.`);
|
||||||
@@ -885,7 +885,7 @@ async function PostDmsBatchWip(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`);
|
||||||
@@ -914,7 +914,7 @@ async function QueryDmsErrWip(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"DEBUG",
|
||||||
`soapClientAccountingGLInsertUpdate.doErrWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientAccountingGLInsertUpdate.doErrWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doErrWIPAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doErrWIPAsync response.`);
|
||||||
@@ -945,7 +945,7 @@ async function DeleteDmsWip(socket) {
|
|||||||
|
|
||||||
CdkBase.createLogEvent(
|
CdkBase.createLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"TRACE",
|
"SILLY",
|
||||||
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
`soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
);
|
);
|
||||||
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`);
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientAccountingGLInsertUpdate.doPostBatchWIPAsync response.`);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ exports.default = async (req, res) => {
|
|||||||
|
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("ioevent-error", "trace", user, null, {
|
logger.log("ioevent-error", "silly", user, null, {
|
||||||
operationname: operationName,
|
operationname: operationName,
|
||||||
time,
|
time,
|
||||||
dbevent,
|
dbevent,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const InstanceManager = require("../utils/instanceMgr").default;
|
|||||||
const winston = require("winston");
|
const winston = require("winston");
|
||||||
const WinstonCloudWatch = require("winston-cloudwatch");
|
const WinstonCloudWatch = require("winston-cloudwatch");
|
||||||
const { isString, isEmpty } = require("lodash");
|
const { isString, isEmpty } = require("lodash");
|
||||||
|
const { networkInterfaces } = require("node:os");
|
||||||
|
|
||||||
const createLogger = () => {
|
const createLogger = () => {
|
||||||
try {
|
try {
|
||||||
@@ -42,6 +43,19 @@ const createLogger = () => {
|
|||||||
})();
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getPrivateIP = () => {
|
||||||
|
const interfaces = networkInterfaces();
|
||||||
|
for (const name of Object.keys(interfaces)) {
|
||||||
|
for (const iface of interfaces[name]) {
|
||||||
|
// Find an IPv4 address that's not internal (like localhost)
|
||||||
|
if (iface.family === "IPv4" && !iface.internal) {
|
||||||
|
return iface.address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "127.0.0.1";
|
||||||
|
};
|
||||||
|
|
||||||
const createProductionTransport = (level, logStreamName, filters) => {
|
const createProductionTransport = (level, logStreamName, filters) => {
|
||||||
return new WinstonCloudWatch({
|
return new WinstonCloudWatch({
|
||||||
level,
|
level,
|
||||||
@@ -51,17 +65,26 @@ const createLogger = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hostname = process.env.HOSTNAME || getPrivateIP();
|
||||||
|
|
||||||
const getDevelopmentTransports = () => [
|
const getDevelopmentTransports = () => [
|
||||||
new winston.transports.Console({
|
new winston.transports.Console({
|
||||||
level: "silly",
|
level: "silly",
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
winston.format.colorize(),
|
winston.format.colorize(),
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp(),
|
||||||
winston.format.printf(({ level, message, timestamp, user, record, object }) => {
|
winston.format.printf(({ level, message, timestamp, user, record, meta }) => {
|
||||||
return `${timestamp} [${level}]: ${message} ${
|
const hostnameColor = `\x1b[34m${hostname}\x1b[0m`; // Blue
|
||||||
user ? `| user: ${JSON.stringify(user)}` : ""
|
const timestampColor = `\x1b[36m${timestamp}\x1b[0m`; // Cyan
|
||||||
} ${record ? `| record: ${JSON.stringify(record)}` : ""} ${
|
const labelColor = "\x1b[33m"; // Yellow
|
||||||
object ? `| object: ${JSON.stringify(object, null, 2)}` : ""
|
const separatorColor = "\x1b[35m|\x1b[0m"; // Magenta for separators
|
||||||
|
|
||||||
|
return `${timestampColor} [${hostnameColor}] [${level}]: ${message} ${
|
||||||
|
user ? `${separatorColor} ${labelColor}user:\x1b[0m ${JSON.stringify(user)}` : ""
|
||||||
|
} ${record ? `${separatorColor} ${labelColor}record:\x1b[0m ${JSON.stringify(record)}` : ""}${
|
||||||
|
meta
|
||||||
|
? `\n${separatorColor} ${labelColor}meta:\x1b[0m ${JSON.stringify(meta, null, 2)} ${separatorColor}`
|
||||||
|
: ""
|
||||||
}`;
|
}`;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -89,6 +112,7 @@ const createLogger = () => {
|
|||||||
message,
|
message,
|
||||||
user,
|
user,
|
||||||
record,
|
record,
|
||||||
|
hostname,
|
||||||
meta
|
meta
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ const redisSocketEvents = ({
|
|||||||
}) => {
|
}) => {
|
||||||
// Logging helper functions
|
// Logging helper functions
|
||||||
const createLogEvent = (socket, level, message) => {
|
const createLogEvent = (socket, level, message) => {
|
||||||
//console.log(`[IOREDIS LOG EVENT] - ${socket?.user?.email} - ${socket.id} - ${message}`);
|
|
||||||
logger.log("ioredis-log-event", level, socket?.user?.email, null, { wsmessage: message });
|
logger.log("ioredis-log-event", level, socket?.user?.email, null, { wsmessage: message });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,7 +32,6 @@ const redisSocketEvents = ({
|
|||||||
next(new Error("Authentication error - no authorization token."));
|
next(new Error("Authentication error - no authorization token."));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//console.log("Uncaught connection error:::", error);
|
|
||||||
logger.log("websocket-connection-error", "error", null, null, {
|
logger.log("websocket-connection-error", "error", null, null, {
|
||||||
...error
|
...error
|
||||||
});
|
});
|
||||||
@@ -43,7 +41,7 @@ const redisSocketEvents = ({
|
|||||||
|
|
||||||
// Register Socket Events
|
// Register Socket Events
|
||||||
const registerSocketEvents = (socket) => {
|
const registerSocketEvents = (socket) => {
|
||||||
createLogEvent(socket, "DEBUG", `Registering RedisIO Socket Events.`);
|
createLogEvent(socket, "debug", `Registering RedisIO Socket Events.`);
|
||||||
|
|
||||||
// Token Update Events
|
// Token Update Events
|
||||||
const registerUpdateEvents = (socket) => {
|
const registerUpdateEvents = (socket) => {
|
||||||
@@ -56,7 +54,7 @@ const redisSocketEvents = ({
|
|||||||
// If We ever want to persist user Data across workers
|
// If We ever want to persist user Data across workers
|
||||||
// await setSessionData(socket.id, "user", user);
|
// await setSessionData(socket.id, "user", user);
|
||||||
|
|
||||||
createLogEvent(socket, "INFO", "Token updated successfully");
|
createLogEvent(socket, "debug", "Token updated successfully");
|
||||||
|
|
||||||
socket.emit("token-updated", { success: true });
|
socket.emit("token-updated", { success: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -67,7 +65,7 @@ const redisSocketEvents = ({
|
|||||||
error: "Stale token."
|
error: "Stale token."
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
createLogEvent(socket, "ERROR", `Token update failed: ${error.message}`);
|
createLogEvent(socket, "error", `Token update failed: ${error.message}`);
|
||||||
socket.emit("token-updated", { success: false, error: error.message });
|
socket.emit("token-updated", { success: false, error: error.message });
|
||||||
// For any other errors, optionally disconnect the socket
|
// For any other errors, optionally disconnect the socket
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
@@ -82,9 +80,9 @@ const redisSocketEvents = ({
|
|||||||
try {
|
try {
|
||||||
const room = getBodyshopRoom(bodyshopUUID);
|
const room = getBodyshopRoom(bodyshopUUID);
|
||||||
socket.join(room);
|
socket.join(room);
|
||||||
createLogEvent(socket, "DEBUG", `Client joined bodyshop room: ${room}`);
|
createLogEvent(socket, "debug", `Client joined bodyshop room: ${room}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLogEvent(socket, "ERROR", `Error joining room: ${error}`);
|
createLogEvent(socket, "error", `Error joining room: ${error}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,9 +90,9 @@ const redisSocketEvents = ({
|
|||||||
try {
|
try {
|
||||||
const room = getBodyshopRoom(bodyshopUUID);
|
const room = getBodyshopRoom(bodyshopUUID);
|
||||||
socket.leave(room);
|
socket.leave(room);
|
||||||
createLogEvent(socket, "DEBUG", `Client left bodyshop room: ${room}`);
|
createLogEvent(socket, "debug", `Client left bodyshop room: ${room}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLogEvent(socket, "ERROR", `Error joining room: ${error}`);
|
createLogEvent(socket, "error", `Error joining room: ${error}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,9 +100,10 @@ const redisSocketEvents = ({
|
|||||||
try {
|
try {
|
||||||
const room = getBodyshopRoom(bodyshopUUID);
|
const room = getBodyshopRoom(bodyshopUUID);
|
||||||
io.to(room).emit("bodyshop-message", message);
|
io.to(room).emit("bodyshop-message", message);
|
||||||
createLogEvent(socket, "DEBUG", `Broadcast message to bodyshop ${room}`);
|
// We do not need this as these can be debugged live
|
||||||
|
// createLogEvent(socket, "debug", `Broadcast message to bodyshop ${room}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLogEvent(socket, "ERROR", `Error getting room: ${error}`);
|
createLogEvent(socket, "error", `Error getting room: ${error}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -115,7 +114,7 @@ const redisSocketEvents = ({
|
|||||||
// Disconnect Events
|
// Disconnect Events
|
||||||
const registerDisconnectEvents = (socket) => {
|
const registerDisconnectEvents = (socket) => {
|
||||||
const disconnect = () => {
|
const disconnect = () => {
|
||||||
createLogEvent(socket, "DEBUG", `User disconnected.`);
|
createLogEvent(socket, "debug", `User disconnected.`);
|
||||||
const rooms = Array.from(socket.rooms).filter((room) => room !== socket.id);
|
const rooms = Array.from(socket.rooms).filter((room) => room !== socket.id);
|
||||||
for (const room of rooms) {
|
for (const room of rooms) {
|
||||||
socket.leave(room);
|
socket.leave(room);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ io.use(function (socket, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
io.on("connection", (socket) => {
|
io.on("connection", (socket) => {
|
||||||
socket.log_level = "TRACE";
|
socket.log_level = "DEBUG";
|
||||||
createLogEvent(socket, "DEBUG", `Connected and Authenticated.`);
|
createLogEvent(socket, "DEBUG", `Connected and Authenticated.`);
|
||||||
|
|
||||||
socket.on("set-log-level", (level) => {
|
socket.on("set-log-level", (level) => {
|
||||||
@@ -75,7 +75,7 @@ io.on("connection", (socket) => {
|
|||||||
socket.on("cdk-calculate-allocations", async (jobid, callback) => {
|
socket.on("cdk-calculate-allocations", async (jobid, callback) => {
|
||||||
const allocations = await CdkCalculateAllocations(socket, jobid);
|
const allocations = await CdkCalculateAllocations(socket, jobid);
|
||||||
createLogEvent(socket, "DEBUG", `Allocations calculated.`);
|
createLogEvent(socket, "DEBUG", `Allocations calculated.`);
|
||||||
createLogEvent(socket, "TRACE", `Allocations calculated. ${JSON.stringify(allocations, null, 2)}`);
|
createLogEvent(socket, "SILLY", `Allocations calculated. ${JSON.stringify(allocations, null, 2)}`);
|
||||||
|
|
||||||
callback(allocations);
|
callback(allocations);
|
||||||
});
|
});
|
||||||
@@ -85,7 +85,7 @@ io.on("connection", (socket) => {
|
|||||||
socket.on("pbs-calculate-allocations", async (jobid, callback) => {
|
socket.on("pbs-calculate-allocations", async (jobid, callback) => {
|
||||||
const allocations = await CdkCalculateAllocations(socket, jobid);
|
const allocations = await CdkCalculateAllocations(socket, jobid);
|
||||||
createLogEvent(socket, "DEBUG", `Allocations calculated.`);
|
createLogEvent(socket, "DEBUG", `Allocations calculated.`);
|
||||||
createLogEvent(socket, "TRACE", `Allocations calculated. ${JSON.stringify(allocations, null, 2)}`);
|
createLogEvent(socket, "SILLY", `Allocations calculated. ${JSON.stringify(allocations, null, 2)}`);
|
||||||
|
|
||||||
callback(allocations);
|
callback(allocations);
|
||||||
});
|
});
|
||||||
@@ -103,7 +103,7 @@ io.on("connection", (socket) => {
|
|||||||
socket.on("pbs-calculate-allocations-ap", async (billids, callback) => {
|
socket.on("pbs-calculate-allocations-ap", async (billids, callback) => {
|
||||||
const allocations = await PbsCalculateAllocationsAp(socket, billids);
|
const allocations = await PbsCalculateAllocationsAp(socket, billids);
|
||||||
createLogEvent(socket, "DEBUG", `AP Allocations calculated.`);
|
createLogEvent(socket, "DEBUG", `AP Allocations calculated.`);
|
||||||
createLogEvent(socket, "TRACE", `Allocations calculated. ${JSON.stringify(allocations, null, 2)}`);
|
createLogEvent(socket, "DEBUG", `Allocations calculated. ${JSON.stringify(allocations, null, 2)}`);
|
||||||
socket.apAllocations = allocations;
|
socket.apAllocations = allocations;
|
||||||
callback(allocations);
|
callback(allocations);
|
||||||
});
|
});
|
||||||
@@ -122,7 +122,7 @@ io.on("connection", (socket) => {
|
|||||||
|
|
||||||
function createLogEvent(socket, level, message) {
|
function createLogEvent(socket, level, message) {
|
||||||
if (LogLevelHierarchy(socket.log_level) >= LogLevelHierarchy(level)) {
|
if (LogLevelHierarchy(socket.log_level) >= LogLevelHierarchy(level)) {
|
||||||
// console.log(`[WS LOG EVENT] ${level} - ${new Date()} - ${socket.user.email} - ${socket.id} - ${message}`);
|
// console.log(`[WS LOG EVENT] ${level} - ${new Date()} - ${socket.user.email} - ${socket.id} - ${message}`);
|
||||||
socket.emit("log-event", {
|
socket.emit("log-event", {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
level,
|
level,
|
||||||
@@ -173,17 +173,17 @@ function createJsonEvent(socket, level, message, json) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createXmlEvent(socket, xml, message, isError = false) {
|
function createXmlEvent(socket, xml, message, isError = false) {
|
||||||
if (LogLevelHierarchy(socket.log_level) >= LogLevelHierarchy("TRACE")) {
|
if (LogLevelHierarchy(socket.log_level) >= LogLevelHierarchy("SILLY")) {
|
||||||
socket.emit("log-event", {
|
socket.emit("log-event", {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
level: isError ? "ERROR" : "TRACE",
|
level: isError ? "ERROR" : "SILLY",
|
||||||
message: `${message}: ${xml}`
|
message: `${message}: ${xml}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log(
|
logger.log(
|
||||||
isError ? "ws-log-event-xml-error" : "ws-log-event-xml",
|
isError ? "ws-log-event-xml-error" : "ws-log-event-xml",
|
||||||
isError ? "ERROR" : "TRACE",
|
isError ? "ERROR" : "SILLY",
|
||||||
socket.user.email,
|
socket.user.email,
|
||||||
socket.recordid,
|
socket.recordid,
|
||||||
{
|
{
|
||||||
@@ -195,7 +195,7 @@ function createXmlEvent(socket, xml, message, isError = false) {
|
|||||||
if (socket.logEvents && isArray(socket.logEvents)) {
|
if (socket.logEvents && isArray(socket.logEvents)) {
|
||||||
socket.logEvents.push({
|
socket.logEvents.push({
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
level: isError ? "ERROR" : "TRACE",
|
level: isError ? "ERROR" : "SILLY",
|
||||||
message,
|
message,
|
||||||
xml
|
xml
|
||||||
});
|
});
|
||||||
@@ -206,7 +206,7 @@ function LogLevelHierarchy(level) {
|
|||||||
switch (level) {
|
switch (level) {
|
||||||
case "XML":
|
case "XML":
|
||||||
return 5;
|
return 5;
|
||||||
case "TRACE":
|
case "SILLY":
|
||||||
return 5;
|
return 5;
|
||||||
case "DEBUG":
|
case "DEBUG":
|
||||||
return 4;
|
return 4;
|
||||||
|
|||||||
Reference in New Issue
Block a user