diff --git a/src/middleware/index.js b/src/middleware/index.js index 50b3740..0fd1234 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -52,7 +52,7 @@ winstonLogger.error("JSON parsing error:", err.message); return next(err); } - winstonLogger.debug("Parsed JSON body:", req.body); + // winstonLogger.debug("Parsed JSON body:", req.body); next(); }); } else if (contentType.includes("application/x-www-form-urlencoded")) { @@ -62,7 +62,7 @@ winstonLogger.error("Form parsing error:", err.message); return next(err); } - winstonLogger.debug("Parsed form body:", req.body); + // winstonLogger.debug("Parsed form body:", req.body); next(); }); } else if (contentType.includes("multipart/form-data")) { @@ -87,11 +87,11 @@ }); return next(jsonErr); } - winstonLogger.warn("Parsed JSON body (fallback):", req.body); + // winstonLogger.warn("Parsed JSON body (fallback):", req.body); next(); }); } else { - winstonLogger.debug("Parsed form body (default):", req.body); + // winstonLogger.debug("Parsed form body (default):", req.body); next(); } }); diff --git a/src/utils/logging.js b/src/utils/logging.js index b9e6d8a..660e795 100644 --- a/src/utils/logging.js +++ b/src/utils/logging.js @@ -216,12 +216,25 @@ let stack = meta.stack || ""; if (stack) delete meta.stack; - let metaString = ""; - if (Object.keys(meta).length > 0) { - metaString = JSON.stringify(meta, null, 2); + // Safely stringify message + let outputMsg; + if (typeof message === "string") { + outputMsg = message; + } else { + try { + outputMsg = JSON.stringify(message, null, 2); + } catch { + outputMsg = util.inspect(message, { depth: null, colors: false }); + } } - return `[${timestamp}] [${level}] ${message}\n${stack}\n${metaString}`; + // Handle meta + let metaString = ""; + if (Object.keys(meta).length > 0) { + metaString = util.inspect(meta, { depth: null, colors: false }); + } + + return `[${timestamp}] [${level}] ${outputMsg}\n${stack}\n${metaString}`; }) ), }), diff --git a/src/utils/structuredLogger.js b/src/utils/structuredLogger.js index 62a7b9e..956d8ec 100644 --- a/src/utils/structuredLogger.js +++ b/src/utils/structuredLogger.js @@ -1,8 +1,6 @@ const { winstonLogger } = require("./logging"); module.exports = (level) => (req, res, next) => { - const start = process.hrtime(); - res.on("finish", () => { const { method, url, headers, query, body, ip, connection } = req; const { statusCode } = res;