feature/IO-2973-Created-By-Tasks - Merge in release, fix conflicts
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -24,7 +24,7 @@ axios.interceptors.request.use((x) => {
|
||||
const printable = `${new Date()} | Request: ${x.method.toUpperCase()} | ${
|
||||
x.url
|
||||
} | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`;
|
||||
console.log(printable);
|
||||
//console.log(printable);
|
||||
|
||||
CdkBase.createJsonEvent(socket, "TRACE", `Raw Request: ${printable}`, x.data);
|
||||
|
||||
@@ -35,7 +35,7 @@ axios.interceptors.response.use((x) => {
|
||||
const socket = x.config.socket;
|
||||
|
||||
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);
|
||||
|
||||
return x;
|
||||
|
||||
@@ -26,7 +26,7 @@ axios.interceptors.request.use((x) => {
|
||||
const printable = `${new Date()} | Request: ${x.method.toUpperCase()} | ${
|
||||
x.url
|
||||
} | ${JSON.stringify(x.data)} | ${JSON.stringify(headers)}`;
|
||||
console.log(printable);
|
||||
//console.log(printable);
|
||||
|
||||
CdkBase.createJsonEvent(socket, "TRACE", `Raw Request: ${printable}`, x.data);
|
||||
|
||||
@@ -37,7 +37,7 @@ axios.interceptors.response.use((x) => {
|
||||
const socket = x.config.socket;
|
||||
|
||||
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);
|
||||
|
||||
return x;
|
||||
|
||||
@@ -207,7 +207,7 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes
|
||||
});
|
||||
|
||||
if (!hasMapaLine && jobs_by_pk.job_totals.rates.mapa.total.amount > 0) {
|
||||
// console.log("Adding MAPA Line Manually.");
|
||||
// //console.log("Adding MAPA Line Manually.");
|
||||
const mapaAccountName = responsibilityCenters.defaults.profits.MAPA;
|
||||
|
||||
const mapaAccount = responsibilityCenters.profits.find((c) => c.name === mapaAccountName);
|
||||
@@ -272,12 +272,12 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes
|
||||
});
|
||||
}
|
||||
} else {
|
||||
//console.log("NO MAPA ACCOUNT FOUND!!");
|
||||
////console.log("NO MAPA ACCOUNT FOUND!!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasMashLine && jobs_by_pk.job_totals.rates.mash.total.amount > 0) {
|
||||
// console.log("Adding MASH Line Manually.");
|
||||
// //console.log("Adding MASH Line Manually.");
|
||||
|
||||
const mashAccountName = responsibilityCenters.defaults.profits.MASH;
|
||||
|
||||
@@ -341,7 +341,7 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// console.log("NO MASH ACCOUNT FOUND!!");
|
||||
// //console.log("NO MASH ACCOUNT FOUND!!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +795,7 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes
|
||||
: taxCodes[taxAccountCode];
|
||||
for (let tyCounter = 1; tyCounter <= 5; tyCounter++) {
|
||||
const taxAmount = Dinero(job_totals.totals.us_sales_tax_breakdown[`ty${tyCounter}Tax`]);
|
||||
console.log(`Tax ${tyCounter}`, taxAmount.toFormat());
|
||||
//console.log(`Tax ${tyCounter}`, taxAmount.toFormat());
|
||||
if (taxAmount.getAmount() > 0) {
|
||||
if (qbo) {
|
||||
InvoiceLineAdd.push({
|
||||
|
||||
@@ -121,7 +121,7 @@ exports.default = async (req, res) => {
|
||||
|
||||
res.status(200).json(ret);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("qbo-payable-create-error", "ERROR", req.user.email, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
|
||||
@@ -182,7 +182,7 @@ exports.default = async (req, res) => {
|
||||
|
||||
res.status(200).json(ret);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("qbo-payment-create-error", "ERROR", req.user.email, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
|
||||
@@ -185,7 +185,7 @@ exports.default = async (req, res) => {
|
||||
error?.response?.data ||
|
||||
error?.message
|
||||
});
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("qbo-receivable-create-error", "ERROR", req.user.email, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -211,7 +211,7 @@ exports.default = async (req, res) => {
|
||||
|
||||
res.status(200).json(ret);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("qbo-receivable-create-error", "ERROR", req.user.email, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
|
||||
@@ -9,7 +9,7 @@ require("dotenv").config({
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
|
||||
exports.createAssociation = async (req, res) => {
|
||||
logger.log("admin-create-association", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-create-association", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true
|
||||
});
|
||||
@@ -31,7 +31,7 @@ exports.createAssociation = async (req, res) => {
|
||||
res.json(result);
|
||||
};
|
||||
exports.createShop = async (req, res) => {
|
||||
logger.log("admin-create-shop", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-create-shop", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true
|
||||
});
|
||||
@@ -64,7 +64,7 @@ exports.createShop = async (req, res) => {
|
||||
}
|
||||
};
|
||||
exports.updateCounter = async (req, res) => {
|
||||
logger.log("admin-update-counter", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-update-counter", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true
|
||||
});
|
||||
@@ -91,7 +91,7 @@ exports.updateCounter = async (req, res) => {
|
||||
}
|
||||
};
|
||||
exports.updateShop = async (req, res) => {
|
||||
logger.log("admin-update-shop", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-update-shop", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ exports.defaultRoute = async function (req, res) {
|
||||
const jobData = await QueryJobData(req, req.BearerToken, req.body.jobid);
|
||||
return res.status(200).json({ data: calculateAllocations(req, jobData) });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
////console.log(error);
|
||||
CdkBase.createLogEvent(req, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`);
|
||||
res.status(500).json({ error: `Error encountered in CdkCalculateAllocations. ${error}` });
|
||||
}
|
||||
@@ -33,7 +33,7 @@ exports.default = async function (socket, jobid) {
|
||||
const jobData = await QueryJobData(socket, "Bearer " + socket.handshake.auth.token, jobid);
|
||||
return calculateAllocations(socket, jobData);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
////console.log(error);
|
||||
CdkBase.createLogEvent(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`);
|
||||
}
|
||||
};
|
||||
@@ -212,7 +212,7 @@ function calculateAllocations(connectionData, job) {
|
||||
});
|
||||
|
||||
if (!hasMapaLine && job.job_totals.rates.mapa.total.amount > 0) {
|
||||
// console.log("Adding MAPA Line Manually.");
|
||||
// //console.log("Adding MAPA Line Manually.");
|
||||
const mapaAccountName = selectedDmsAllocationConfig.profits.MAPA;
|
||||
|
||||
const mapaAccount = bodyshop.md_responsibility_centers.profits.find((c) => c.name === mapaAccountName);
|
||||
@@ -224,7 +224,7 @@ function calculateAllocations(connectionData, job) {
|
||||
Dinero(job.job_totals.rates.mapa.total)
|
||||
);
|
||||
} else {
|
||||
//console.log("NO MAPA ACCOUNT FOUND!!");
|
||||
////console.log("NO MAPA ACCOUNT FOUND!!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -820,7 +820,7 @@ exports.default = async (req, res) => {
|
||||
job: JSON.stringify({ id: job.id, ro_number: job.ro_number }),
|
||||
error: error.message || JSON.stringify(error)
|
||||
});
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.log("arms-failed-job", "ERROR", "api", job.shopid, {
|
||||
@@ -886,7 +886,10 @@ exports.default = async (req, res) => {
|
||||
const [result, rawResponse, , rawRequest] = entegralResponse;
|
||||
} catch (error) {
|
||||
fs.writeFileSync(`./logs/${xmlObj.filename}`, xmlObj.xml);
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("arms-error-shop", "ERROR", "api", bodyshop.id, {
|
||||
error
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
//Error at the shop level.
|
||||
|
||||
@@ -206,9 +206,6 @@ const CreateRepairOrderTag = (job, errorCallback) => {
|
||||
|
||||
const repairCosts = CreateCosts(job);
|
||||
|
||||
if (job.ro_number === "QBD209") {
|
||||
console.log("Stop here");
|
||||
}
|
||||
//Calculate detail only lines.
|
||||
const detailAdjustments = job.joblines
|
||||
.filter((jl) => jl.ah_detail_line && jl.mod_lbr_ty)
|
||||
|
||||
@@ -154,7 +154,7 @@ exports.default = async (req, res) => {
|
||||
async function getPrivateKey() {
|
||||
// Connect to AWS Secrets Manager
|
||||
const client = new SecretsManagerClient({ region: "ca-central-1" });
|
||||
const command = new GetSecretValueCommand({ SecretId: CHATTER_PRIVATE_KEY });
|
||||
const command = new GetSecretValueCommand({ SecretId: "CHATTER_PRIVATE_KEY" });
|
||||
|
||||
logger.log("chatter-get-private-key", "DEBUG", "api", null, null);
|
||||
try {
|
||||
|
||||
@@ -16,7 +16,7 @@ admin.initializeApp({
|
||||
});
|
||||
|
||||
const createUser = async (req, res) => {
|
||||
logger.log("admin-create-user", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-create-user", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true
|
||||
});
|
||||
@@ -97,7 +97,7 @@ const sendPromanagerWelcomeEmail = (req, res) => {
|
||||
|
||||
// Validate email before proceeding
|
||||
if (!dbUser.validemail) {
|
||||
logger.log("admin-send-welcome-email-skip", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
|
||||
message: "User email is not valid, skipping email.",
|
||||
email
|
||||
});
|
||||
@@ -107,7 +107,7 @@ const sendPromanagerWelcomeEmail = (req, res) => {
|
||||
// Check if the user's company is ProManager
|
||||
const convenientCompany = dbUser.associations?.[0]?.bodyshop?.convenient_company;
|
||||
if (convenientCompany !== "promanager") {
|
||||
logger.log("admin-send-welcome-email-skip", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-send-welcome-email-skip", "debug", req.user.email, null, {
|
||||
message: 'convenient_company is not "promanager", skipping email.',
|
||||
convenientCompany
|
||||
});
|
||||
@@ -141,7 +141,7 @@ const sendPromanagerWelcomeEmail = (req, res) => {
|
||||
})
|
||||
.then(() => {
|
||||
// Log success and return response
|
||||
logger.log("admin-send-welcome-email", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-send-welcome-email", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true,
|
||||
emailSentTo: email
|
||||
@@ -161,7 +161,7 @@ const sendPromanagerWelcomeEmail = (req, res) => {
|
||||
};
|
||||
|
||||
const updateUser = (req, res) => {
|
||||
logger.log("admin-update-user", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-update-user", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true
|
||||
});
|
||||
@@ -184,7 +184,7 @@ const updateUser = (req, res) => {
|
||||
.then((userRecord) => {
|
||||
// See the UserRecord reference doc for the contents of userRecord.
|
||||
|
||||
logger.log("admin-update-user-success", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-update-user-success", "debug", req.user.email, null, {
|
||||
userRecord,
|
||||
ioadmin: true
|
||||
});
|
||||
@@ -199,7 +199,7 @@ const updateUser = (req, res) => {
|
||||
};
|
||||
|
||||
const getUser = (req, res) => {
|
||||
logger.log("admin-get-user", "ADMIN", req.user.email, null, {
|
||||
logger.log("admin-get-user", "debug", req.user.email, null, {
|
||||
request: req.body,
|
||||
ioadmin: true
|
||||
});
|
||||
@@ -321,7 +321,7 @@ module.exports = {
|
||||
// admin.auth().setCustomUserClaims(uid, {
|
||||
// ioadmin: true,
|
||||
// "https://hasura.io/jwt/claims": {
|
||||
// "x-hasura-default-role": "admin",
|
||||
// "x-hasura-default-role": "debug",
|
||||
// "x-hasura-allowed-roles": ["admin"],
|
||||
// "x-hasura-user-id": uid,
|
||||
// },
|
||||
|
||||
@@ -78,7 +78,7 @@ exports.lightbox_credentials = async (req, res) => {
|
||||
|
||||
res.send(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("intellipay-lightbox-credentials-error", "ERROR", req.user?.email, null, {
|
||||
error: JSON.stringify(error)
|
||||
});
|
||||
@@ -109,7 +109,7 @@ exports.payment_refund = async (req, res) => {
|
||||
|
||||
res.send(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("intellipay-refund-error", "ERROR", req.user?.email, null, {
|
||||
error: JSON.stringify(error)
|
||||
});
|
||||
@@ -143,7 +143,7 @@ exports.generate_payment_url = async (req, res) => {
|
||||
|
||||
res.send(response.data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("intellipay-payment-url-error", "ERROR", req.user?.email, null, {
|
||||
error: JSON.stringify(error)
|
||||
});
|
||||
|
||||
@@ -28,10 +28,10 @@ exports.default = async (req, res) => {
|
||||
// }
|
||||
// });
|
||||
|
||||
ioRedis.to(getBodyshopRoom(bodyshopid)).emit("bodyshop-message", {
|
||||
operationName,
|
||||
useremail
|
||||
});
|
||||
// ioRedis.to(getBodyshopRoom(bodyshopid)).emit("bodyshop-message", {
|
||||
// operationName,
|
||||
// useremail
|
||||
// });
|
||||
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
|
||||
@@ -866,8 +866,8 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
}
|
||||
});
|
||||
|
||||
console.log("*** Taxable Amounts***");
|
||||
console.table(JSON.parse(JSON.stringify(taxableAmounts)));
|
||||
// console.log("*** Taxable Amounts***");
|
||||
// console.table(JSON.parse(JSON.stringify(taxableAmounts)));
|
||||
|
||||
//For the taxable amounts, figure out which tax type applies.
|
||||
//Then sum up the total of that tax type and then calculate the thresholds.
|
||||
@@ -979,8 +979,8 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
}
|
||||
|
||||
const remainingTaxableAmounts = taxableAmountsByTier;
|
||||
console.log("*** Taxable Amounts by Tier***");
|
||||
console.table(JSON.parse(JSON.stringify(taxableAmountsByTier)));
|
||||
// console.log("*** Taxable Amounts by Tier***");
|
||||
// console.table(JSON.parse(JSON.stringify(taxableAmountsByTier)));
|
||||
|
||||
Object.keys(taxableAmountsByTier).forEach((taxTierKey) => {
|
||||
try {
|
||||
@@ -1030,8 +1030,8 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
}
|
||||
});
|
||||
|
||||
console.log("*** Total Tax by Tier Amounts***");
|
||||
console.table(JSON.parse(JSON.stringify(totalTaxByTier)));
|
||||
// console.log("*** Total Tax by Tier Amounts***");
|
||||
// console.table(JSON.parse(JSON.stringify(totalTaxByTier)));
|
||||
|
||||
stateTax = stateTax
|
||||
.add(totalTaxByTier.ty1Tax)
|
||||
|
||||
@@ -182,7 +182,7 @@ async function AutoAddAtsIfRequired({ job, client }) {
|
||||
job.joblines[atsLineIndex].act_price = atsAmount;
|
||||
}
|
||||
|
||||
console.log(job.jobLines);
|
||||
//console.log(job.jobLines);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ async function OpenSearchUpdateHandler(req, res) {
|
||||
};
|
||||
|
||||
const response = await osClient.index(payload);
|
||||
console.log(response.body);
|
||||
//console.log(response.body);
|
||||
res.status(200).json(response.body);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -255,7 +255,7 @@ async function OpenSearchSearchHandler(req, res) {
|
||||
|
||||
res.json(body);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//console.log(error);
|
||||
logger.log("os-search-error", "ERROR", req.user.email, null, {
|
||||
error: JSON.stringify(error)
|
||||
});
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
const { createCanvas } = require("canvas");
|
||||
const Chart = require("chart.js/auto");
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const { backgroundColors, borderColors } = require("./canvas-colors");
|
||||
const { isObject, defaultsDeep, isNumber } = require("lodash");
|
||||
|
||||
exports.canvastest = function (req, res) {
|
||||
console.log("Incoming test request.", req);
|
||||
//console.log("Incoming test request.", req);
|
||||
res.status(200).send("OK");
|
||||
};
|
||||
|
||||
exports.canvas = function (req, res) {
|
||||
const { w, h, values, keys, override } = req.body;
|
||||
console.log("Incoming Canvas Request:", w, h, values, keys, override);
|
||||
|
||||
//console.log("Incoming Canvas Request:", w, h, values, keys, override);
|
||||
logger.log("inbound-canvas-creation", "debug", "jsr", null, { w, h, values, keys, override });
|
||||
// Gate required values
|
||||
if (!values || !keys) {
|
||||
res.status(400).send("Missing required data");
|
||||
|
||||
@@ -47,7 +47,7 @@ exports.receive = async (req, res) => {
|
||||
//Found a bodyshop - should always happen.
|
||||
if (response.bodyshops[0].conversations.length === 0) {
|
||||
//No conversation Found, create one.
|
||||
console.log("[SMS Receive] No conversation found. Creating one.");
|
||||
//console.log("[SMS Receive] No conversation found. Creating one.");
|
||||
newMessage.conversation = {
|
||||
data: {
|
||||
bodyshopid: response.bodyshops[0].id,
|
||||
@@ -56,7 +56,7 @@ exports.receive = async (req, res) => {
|
||||
};
|
||||
} else if (response.bodyshops[0].conversations.length === 1) {
|
||||
//Just add it to the conversation
|
||||
console.log("[SMS Receive] Conversation found. Added ID.");
|
||||
//console.log("[SMS Receive] Conversation found. Added ID.");
|
||||
newMessage.conversationid = response.bodyshops[0].conversations[0].id;
|
||||
} else {
|
||||
//We should never get here.
|
||||
@@ -123,7 +123,14 @@ exports.receive = async (req, res) => {
|
||||
}
|
||||
}
|
||||
} catch (e1) {
|
||||
console.log("e1", e1);
|
||||
logger.log("sms-inbound-error", "ERROR", "api", null, {
|
||||
msid: req.body.SmsMessageSid,
|
||||
text: req.body.Body,
|
||||
image: !!req.body.MediaUrl0,
|
||||
image_path: generateMediaArray(req.body),
|
||||
messagingServiceSid: req.body.MessagingServiceSid,
|
||||
error: e1
|
||||
});
|
||||
res.sendStatus(500).json(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,109 @@
|
||||
const graylog2 = require("graylog2");
|
||||
|
||||
const logger = new graylog2.graylog({
|
||||
servers: [{ host: "logs.bodyshop.app", port: 12201 }]
|
||||
// Load environment variables THIS MUST BE AT THE TOP
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
function log(message, type, user, record, object) {
|
||||
if (type !== "ioevent")
|
||||
console.log(message, {
|
||||
type,
|
||||
env: process.env.NODE_ENV || "development",
|
||||
user,
|
||||
record,
|
||||
...object
|
||||
});
|
||||
logger.log(message, message, {
|
||||
type,
|
||||
env: process.env.NODE_ENV || "development",
|
||||
user,
|
||||
record,
|
||||
...object
|
||||
});
|
||||
}
|
||||
const InstanceManager = require("../utils/instanceMgr").default;
|
||||
const winston = require("winston");
|
||||
const WinstonCloudWatch = require("winston-cloudwatch");
|
||||
const { isString, isEmpty } = require("lodash");
|
||||
|
||||
module.exports = { log };
|
||||
const createLogger = () => {
|
||||
try {
|
||||
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
|
||||
const logGroupName = isLocal ? "development" : process.env.CLOUDWATCH_LOG_GROUP;
|
||||
|
||||
const winstonCloudwatchTransportDefaults = {
|
||||
logGroupName: logGroupName,
|
||||
awsOptions: {
|
||||
region: InstanceManager({
|
||||
imex: "ca-central-1",
|
||||
rome: "us-east-2"
|
||||
})
|
||||
},
|
||||
jsonMessage: true
|
||||
};
|
||||
|
||||
if (isLocal) {
|
||||
winstonCloudwatchTransportDefaults.awsOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
|
||||
console.log(
|
||||
`Winston Transports set to LocalStack end point: ${winstonCloudwatchTransportDefaults.awsOptions.endpoint}`
|
||||
);
|
||||
}
|
||||
|
||||
const levelFilter = (levels) => {
|
||||
return winston.format((info) => {
|
||||
if (Array.isArray(levels)) {
|
||||
return levels.includes(info.level) ? info : false;
|
||||
} else {
|
||||
return info.level === levels ? info : false;
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
const createProductionTransport = (level, logStreamName, filters) => {
|
||||
return new WinstonCloudWatch({
|
||||
level,
|
||||
logStreamName: logStreamName || level,
|
||||
format: levelFilter(filters || level),
|
||||
...winstonCloudwatchTransportDefaults
|
||||
});
|
||||
};
|
||||
|
||||
const getDevelopmentTransports = () => [
|
||||
new winston.transports.Console({
|
||||
level: "silly",
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(({ level, message, timestamp, user, record, object }) => {
|
||||
return `${timestamp} [${level}]: ${message} ${
|
||||
user ? `| user: ${JSON.stringify(user)}` : ""
|
||||
} ${record ? `| record: ${JSON.stringify(record)}` : ""} ${
|
||||
object ? `| object: ${JSON.stringify(object, null, 2)}` : ""
|
||||
}`;
|
||||
})
|
||||
)
|
||||
})
|
||||
];
|
||||
|
||||
const getProductionTransports = () => [
|
||||
createProductionTransport("error"),
|
||||
createProductionTransport("warn"),
|
||||
createProductionTransport("info"),
|
||||
createProductionTransport("silly", "debug", ["http", "verbose", "debug", "silly"])
|
||||
];
|
||||
|
||||
const winstonLogger = winston.createLogger({
|
||||
format: winston.format.json(),
|
||||
transports:
|
||||
process.env.NODE_ENV === "production"
|
||||
? getProductionTransports()
|
||||
: [...getDevelopmentTransports(), ...getProductionTransports()]
|
||||
});
|
||||
|
||||
const log = (message, type, user, record, meta) => {
|
||||
winstonLogger.log({
|
||||
level: type.toLowerCase(),
|
||||
message,
|
||||
user,
|
||||
record,
|
||||
meta
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
log,
|
||||
logger: winstonLogger
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Error setting up enhanced Logger, defaulting to console.: " + e?.message || "");
|
||||
return {
|
||||
log: console.log,
|
||||
logger: console.log
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = createLogger();
|
||||
|
||||
@@ -8,7 +8,7 @@ const redisSocketEvents = ({
|
||||
}) => {
|
||||
// Logging helper functions
|
||||
const createLogEvent = (socket, level, message) => {
|
||||
console.log(`[IOREDIS LOG EVENT] - ${socket?.user?.email} - ${socket.id} - ${message}`);
|
||||
//console.log(`[IOREDIS LOG EVENT] - ${socket?.user?.email} - ${socket.id} - ${message}`);
|
||||
logger.log("ioredis-log-event", level, socket?.user?.email, null, { wsmessage: message });
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ const redisSocketEvents = ({
|
||||
next(new Error("Authentication error - no authorization token."));
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Uncaught connection error:::", error);
|
||||
//console.log("Uncaught connection error:::", error);
|
||||
logger.log("websocket-connection-error", "error", null, null, {
|
||||
...error
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ io.use(function (socket, next) {
|
||||
next(new Error("Authentication error - no authorization token."));
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Uncaught connection error:::", error);
|
||||
//console.log("Uncaught connection error:::", error);
|
||||
logger.log("websocket-connection-error", "error", null, null, {
|
||||
token: socket.handshake.auth.token,
|
||||
...error
|
||||
@@ -122,7 +122,7 @@ io.on("connection", (socket) => {
|
||||
|
||||
function createLogEvent(socket, level, message) {
|
||||
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", {
|
||||
timestamp: new Date(),
|
||||
level,
|
||||
@@ -148,7 +148,7 @@ function createLogEvent(socket, level, message) {
|
||||
|
||||
function createJsonEvent(socket, level, message, json) {
|
||||
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", {
|
||||
timestamp: new Date(),
|
||||
level,
|
||||
|
||||
Reference in New Issue
Block a user