mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-01 14:09:57 -05:00
Merge pull request #2513 from bluewave-labs/feat/queue-page-update
feat: move queue to logs page
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { handleError } from "./controllerUtils.js";
|
||||
|
||||
const SERVICE_NAME = "JobQueueController";
|
||||
|
||||
class LogController {
|
||||
constructor(logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
getLogs = async (req, res, next) => {
|
||||
try {
|
||||
const logs = await this.logger.getLogs();
|
||||
res.success({
|
||||
msg: "Logs fetched successfully",
|
||||
data: logs,
|
||||
});
|
||||
} catch (error) {
|
||||
next(handleError(error, SERVICE_NAME, "getLogs"));
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
export default LogController;
|
||||
@@ -36,6 +36,9 @@ import StatusPageController from "./controllers/statusPageController.js";
|
||||
import QueueRoutes from "./routes/queueRoute.js";
|
||||
import QueueController from "./controllers/queueController.js";
|
||||
|
||||
import LogRoutes from "./routes/logRoutes.js";
|
||||
import LogController from "./controllers/logController.js";
|
||||
|
||||
import NotificationRoutes from "./routes/notificationRoute.js";
|
||||
import NotificationController from "./controllers/notificationController.js";
|
||||
|
||||
@@ -294,6 +297,8 @@ const startApp = async () => {
|
||||
ServiceRegistry.get(StringService.SERVICE_NAME)
|
||||
);
|
||||
|
||||
const logController = new LogController(logger);
|
||||
|
||||
const statusPageController = new StatusPageController(
|
||||
ServiceRegistry.get(MongoDB.SERVICE_NAME),
|
||||
ServiceRegistry.get(StringService.SERVICE_NAME)
|
||||
@@ -320,6 +325,7 @@ const startApp = async () => {
|
||||
maintenanceWindowController
|
||||
);
|
||||
const queueRoutes = new QueueRoutes(queueController);
|
||||
const logRoutes = new LogRoutes(logController);
|
||||
const statusPageRoutes = new StatusPageRoutes(statusPageController);
|
||||
|
||||
const notificationRoutes = new NotificationRoutes(notificationController);
|
||||
@@ -372,6 +378,7 @@ const startApp = async () => {
|
||||
app.use("/api/v1/checks", verifyJWT, checkRoutes.getRouter());
|
||||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRoutes.getRouter());
|
||||
app.use("/api/v1/queue", verifyJWT, queueRoutes.getRouter());
|
||||
app.use("/api/v1/logs", verifyJWT, logRoutes.getRouter());
|
||||
app.use("/api/v1/status-page", statusPageRoutes.getRouter());
|
||||
app.use("/api/v1/notifications", verifyJWT, notificationRoutes.getRouter());
|
||||
app.use("/api/v1/diagnostic", verifyJWT, diagnosticRoutes.getRouter());
|
||||
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
import { Router } from "express";
|
||||
import { isAllowed } from "../middleware/isAllowed.js";
|
||||
class LogRoutes {
|
||||
constructor(logController) {
|
||||
this.router = Router();
|
||||
this.logController = logController;
|
||||
this.initRoutes();
|
||||
}
|
||||
initRoutes() {
|
||||
this.router.get("/", isAllowed(["admin", "superadmin"]), this.logController.getLogs);
|
||||
}
|
||||
|
||||
getRouter() {
|
||||
return this.router;
|
||||
}
|
||||
}
|
||||
|
||||
export default LogRoutes;
|
||||
+33
-18
@@ -4,6 +4,8 @@ dotenv.config();
|
||||
|
||||
class Logger {
|
||||
constructor() {
|
||||
this.logCache = [];
|
||||
this.maxCacheSize = 1000;
|
||||
const consoleFormat = format.printf(
|
||||
({ level, message, service, method, details, timestamp, stack }) => {
|
||||
if (message instanceof Object) {
|
||||
@@ -72,11 +74,9 @@ class Logger {
|
||||
* @param {Object} config.details - Additional details.
|
||||
*/
|
||||
info(config) {
|
||||
this.logger.info(config.message, {
|
||||
service: config.service,
|
||||
method: config.method,
|
||||
details: config.details,
|
||||
});
|
||||
const logEntry = this.buildLogEntry("info", config);
|
||||
this.cacheLog(logEntry);
|
||||
this.logger.info(config.message, logEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,11 +88,9 @@ class Logger {
|
||||
* @param {Object} config.details - Additional details.
|
||||
*/
|
||||
warn(config) {
|
||||
this.logger.warn(config.message, {
|
||||
service: config.service,
|
||||
method: config.method,
|
||||
details: config.details,
|
||||
});
|
||||
const logEntry = this.buildLogEntry("warn", config);
|
||||
this.cacheLog(logEntry);
|
||||
this.logger.warn(config.message, logEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,12 +102,9 @@ class Logger {
|
||||
* @param {Object} config.details - Additional details.
|
||||
*/
|
||||
error(config) {
|
||||
this.logger.error(config.message, {
|
||||
service: config.service,
|
||||
method: config.method,
|
||||
details: config.details,
|
||||
stack: config.stack,
|
||||
});
|
||||
const logEntry = this.buildLogEntry("error", config);
|
||||
this.cacheLog(logEntry);
|
||||
this.logger.error(config.message, logEntry);
|
||||
}
|
||||
/**
|
||||
* Logs a debug message.
|
||||
@@ -120,12 +115,32 @@ class Logger {
|
||||
* @param {Object} config.details - Additional details.
|
||||
*/
|
||||
debug(config) {
|
||||
this.logger.debug(config.message, {
|
||||
const logEntry = this.buildLogEntry("debug", config);
|
||||
this.cacheLog(logEntry);
|
||||
this.logger.debug(config.message, logEntry);
|
||||
}
|
||||
|
||||
cacheLog(entry) {
|
||||
this.logCache.push(entry);
|
||||
if (this.logCache.length > this.maxCacheSize) {
|
||||
this.logCache.shift();
|
||||
}
|
||||
}
|
||||
|
||||
getLogs() {
|
||||
return this.logCache;
|
||||
}
|
||||
|
||||
buildLogEntry(level, config) {
|
||||
return {
|
||||
level,
|
||||
message: config.message,
|
||||
service: config.service,
|
||||
method: config.method,
|
||||
details: config.details,
|
||||
stack: config.stack,
|
||||
});
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user