diff --git a/public/js/logs.js b/public/js/logs.js
index f6408d7..3249a1f 100644
--- a/public/js/logs.js
+++ b/public/js/logs.js
@@ -165,8 +165,6 @@
this.hasMore = data.pagination.hasMore;
this.totalPages = data.pagination.totalPages;
- console.log(data.logs);
-
if (data.logs.length === 0 && !append) {
this.tbody.innerHTML = '
| No logs found |
';
this.updatePaginationInfo(0, 0, 0);
diff --git a/src/app.js b/src/app.js
index d9b02e7..7e94c95 100644
--- a/src/app.js
+++ b/src/app.js
@@ -3,7 +3,8 @@
const net = require("net");
const setupMiddleware = require("./middleware");
-const { manualLogger } = require("./utils/logging");
+const { winstonLogger } = require("./utils/logging");
+
const { startTokenCleanup } = require("./utils/tokenCleanup");
const SERVER_PORT = process.env.TEST_PORT || process.env.SERVER_PORT || 3400;
@@ -15,15 +16,13 @@
const UNHANDLED_REJECTION_MSG = "Unhandled Rejection:";
function handleUncaughtException(err) {
- manualLogger.error(UNCUGHT_EXCEPTION_MSG, err.stack || err);
+ winstonLogger.error(UNCUGHT_EXCEPTION_MSG, err.stack || err);
}
function handleUnhandledRejection(reason) {
- manualLogger.error(UNHANDLED_REJECTION_MSG, reason?.stack || reason);
+ winstonLogger.error(UNHANDLED_REJECTION_MSG, reason?.stack || reason);
}
-console.log(CWD_LOG);
-
startTokenCleanup();
const app = setupMiddleware();
@@ -31,7 +30,7 @@
const server = net.createServer();
server.once("error", (err) => {
if (err.code === "EADDRINUSE") {
- console.error(`Port ${SERVER_PORT} is already in use.`);
+ winstonLogger.error(`Port ${SERVER_PORT} is already in use.`);
process.exit(1);
} else {
throw err;
@@ -42,8 +41,8 @@
server.close();
app.listen(SERVER_PORT, () => {
- console.log(SERVER_LISTEN_LOG(SERVER_PORT));
- console.log(NODE_ENV_LOG);
+ winstonLogger.info(SERVER_LISTEN_LOG(SERVER_PORT));
+ winstonLogger.info(NODE_ENV_LOG);
});
});
diff --git a/src/middleware/errorHandler.js b/src/middleware/errorHandler.js
index d6931f5..42365c6 100644
--- a/src/middleware/errorHandler.js
+++ b/src/middleware/errorHandler.js
@@ -11,6 +11,7 @@
DEFAULT_LOG_LEVEL,
ERROR_REDIRECT_PATH,
} = require("../constants/errorConstants");
+const { winstonLogger } = require("../utils/logging");
module.exports = async (err, req, res, next) => {
const statusCode = err.statusCode ?? DEFAULT_STATUS_CODE;
@@ -39,9 +40,9 @@
if (req?.log?.error) {
req.log.error(logEntry); // fixme, logs arent logging?
- console.log(logEntry);
+ winstonLogger.error(logEntry);
} else {
- console.error(logEntry);
+ winstonLogger.error(logEntry);
}
const errorContext = getErrorContext(code || statusCode);
diff --git a/src/middleware/index.js b/src/middleware/index.js
index f963d06..50b3740 100644
--- a/src/middleware/index.js
+++ b/src/middleware/index.js
@@ -13,6 +13,7 @@
const hbs = require("./hbs");
const authCheck = require("./authCheck");
const { redirectMiddleware } = require("./redirect");
+const { winstonLogger } = require("../utils/logging");
const {
TRUST_PROXY,
@@ -42,54 +43,55 @@
const isExcludedPath = EXCLUDED_PATHS.includes(req.path);
const limit = isExcludedPath ? RAW_BODY_LIMIT_BYTES : DATA_LIMIT_BYTES;
- console.log(`Processing ${req.method} ${req.path}`);
- console.log(`Content-Type: ${req.get("content-type")}`);
- console.log(`Is excluded path: ${isExcludedPath}, using limit: ${limit}`);
-
const contentType = req.get("content-type") || "";
if (contentType.includes("application/json")) {
// Parse JSON with appropriate limit
express.json({ limit })(req, res, (err) => {
if (err) {
- console.log("JSON parsing error:", err.message);
+ winstonLogger.error("JSON parsing error:", err.message);
return next(err);
}
- console.log("Parsed JSON body:", req.body);
+ winstonLogger.debug("Parsed JSON body:", req.body);
next();
});
} else if (contentType.includes("application/x-www-form-urlencoded")) {
// Parse form data with appropriate limit
express.urlencoded({ extended: false, limit })(req, res, (err) => {
if (err) {
- console.log("Form parsing error:", err.message);
+ winstonLogger.error("Form parsing error:", err.message);
return next(err);
}
- console.log("Parsed form body:", req.body);
+ winstonLogger.debug("Parsed form body:", req.body);
next();
});
} else if (contentType.includes("multipart/form-data")) {
// For multipart, we'd need multer or similar, but pass through for now
- console.log("Multipart form detected - may need additional handling");
+ winstonLogger.debug(
+ "Multipart form detected - may need additional handling"
+ );
next();
} else {
// Try form parsing first (most common for HTML forms), then JSON
express.urlencoded({ extended: false, limit })(req, res, (formErr) => {
if (formErr) {
- console.log("Form parsing failed, trying JSON:", formErr.message);
+ winstonLogger.warn(
+ "Form parsing failed, trying JSON:",
+ formErr.message
+ );
express.json({ limit })(req, res, (jsonErr) => {
if (jsonErr) {
- console.log("Both parsers failed:", {
+ winstonLogger.error("Both parsers failed:", {
formErr: formErr.message,
jsonErr: jsonErr.message,
});
return next(jsonErr);
}
- console.log("Parsed JSON body (fallback):", req.body);
+ winstonLogger.warn("Parsed JSON body (fallback):", req.body);
next();
});
} else {
- console.log("Parsed form body (default):", req.body);
+ winstonLogger.debug("Parsed form body (default):", req.body);
next();
}
});
diff --git a/src/routes/docs.js b/src/routes/docs.js
index 41b4d28..65bc861 100644
--- a/src/routes/docs.js
+++ b/src/routes/docs.js
@@ -10,6 +10,8 @@
const { baseUrl } = require("../utils/baseUrl");
const { qualifyLink } = require("../utils/qualifyLinks");
+const { winstonLogger, manualLogger } = require("../utils/logging");
+
const docsDir = path.join(__dirname, "../../content/docs");
let docsCache = {}; // { [path]: { modules: {}, crossCuttingSummary: {} } }
async function loadDocFile(filePath) {
@@ -19,48 +21,17 @@
const fileContent = await fs.readFile(fullPath, "utf-8");
const parsed = yaml.load(fileContent);
const crossCuttingSummary = parsed["Cross Cutting Summary"] || null;
- console.log(
- `Cross cutting summary: ${JSON.stringify(crossCuttingSummary, 0, 2)}`
- );
docsCache[filePath] = {
modules: parsed,
crossCuttingSummary,
};
return docsCache[filePath];
} catch (e) {
- console.error(e.stack);
+ manualLogger.error(e.stack);
return null;
}
}
-// function filterSecurityAndStabilityKeys(docResult) {
-// if (!docResult || !docResult.modules) {
-// return docResult;
-// }
-
-// const filteredModules = {};
-
-// for (const [key, value] of Object.entries(docResult.modules)) {
-// // Skip modules whose keys start with 'securityAndStability:'
-// if (key.startsWith("securityAndStability:")) {
-// continue;
-// }
-
-// // For other modules, remove the securityAndStability property if it exists
-// if (value && typeof value === "object") {
-// const { securityAndStability, ...moduleWithoutSecurity } = value;
-// filteredModules[key] = moduleWithoutSecurity;
-// } else {
-// filteredModules[key] = value;
-// }
-// }
-
-// return {
-// ...docResult,
-// modules: filteredModules,
-// };
-// }
-
// Helper function to filter security from a single module
function filterModuleSecurityKeys(moduleDoc) {
if (!moduleDoc || typeof moduleDoc !== "object") {
diff --git a/src/services/sitemapService.js b/src/services/sitemapService.js
index a32c462..ac1f4eb 100644
--- a/src/services/sitemapService.js
+++ b/src/services/sitemapService.js
@@ -8,6 +8,7 @@
const glob = require("fast-glob");
const { qualifySitemapLinks } = require("../utils/qualifyLinks");
+const { winstonLogger } = require("../utils/logging");
const CONTENT_ROOT = path.resolve(__dirname, "../../content");
const pattern = `${CONTENT_ROOT}/**/*.md`;
@@ -157,7 +158,7 @@
}
entries.push(parentEntry);
- console.log(
+ winstonLogger.debug(
`Added docs entry: ${parentEntry.loc} with ${parentEntry.children.length} children`
);
}
@@ -172,7 +173,7 @@
);
if (index !== -1) {
- console.log(
+ winstonLogger.debug(
`Found placeholder #inject:${key}, injecting ${items.length} items`
);
// Replace the placeholder with the actual items
diff --git a/src/utils/diskSpaceMonitor.js b/src/utils/diskSpaceMonitor.js
index 1413d1c..730b734 100644
--- a/src/utils/diskSpaceMonitor.js
+++ b/src/utils/diskSpaceMonitor.js
@@ -3,6 +3,7 @@
const path = require("path");
const { promisify } = require("util");
const statvfs = promisify(require("statvfs"));
+const { winstonLogger } = require("./logging");
class DiskSpaceMonitor {
constructor(logDir, options = {}) {
@@ -173,14 +174,14 @@
this.lastCleanupTime = new Date().toISOString();
this.diskSpaceStatus.autoCleanupPerformed = true;
- console.log(
+ winstonLogger.warn(
`Cleanup completed: ${deletedFiles} files/directories deleted, ${freedSpace.toFixed(2)} GB freed`
);
return { deletedFiles, freedSpace };
}
async performEmergencyCleanup() {
- console.log("Performing emergency cleanup...");
+ winstonLogger.warn("Performing emergency cleanup...");
// More aggressive cleanup - keep only last 24 hours of logs
const cutoffDate = new Date();
diff --git a/src/utils/sendContactMail.js b/src/utils/sendContactMail.js
index 36a0165..c4e0522 100644
--- a/src/utils/sendContactMail.js
+++ b/src/utils/sendContactMail.js
@@ -50,6 +50,7 @@
await fs.writeFile(EMAIL_LOG_PATH, JSON.stringify(logs, null, 2));
} catch (err) {
console.error("Failed to log email to file:", err);
+ throw err;
}
return transporter.sendMail(mailData);
diff --git a/src/utils/tokenCleanup.js b/src/utils/tokenCleanup.js
index 8bdd5a4..5ce582e 100644
--- a/src/utils/tokenCleanup.js
+++ b/src/utils/tokenCleanup.js
@@ -1,5 +1,6 @@
// src/utils/tokenCleanup.js
const { cleanupTokens } = require("./adminToken");
+const { winstonLogger } = require("./logging");
// Set up periodic cleanup (run every 5 minutes)
const CLEANUP_INTERVAL = 5 * 60 * 1000; // 5 minutes
@@ -7,7 +8,7 @@
function startTokenCleanup() {
setInterval(() => {
cleanupTokens();
- console.log("Cleaned up expired pre-auth tokens");
+ winstonLogger.debug("Cleaned up expired pre-auth tokens");
}, CLEANUP_INTERVAL);
}