Compare commits

...

2 Commits

Author SHA1 Message Date
b48fe51f46 chore: add debug logs to middleware
Some checks failed
Build & Push Docker Image / build (push) Successful in 24s
Test & Build / build (push) Has been cancelled
2025-05-27 12:16:19 +01:00
27ecf0f9b2 chore: change log format to timestamp before filename 2025-05-27 12:15:54 +01:00
3 changed files with 15 additions and 3 deletions

View File

@ -11,7 +11,7 @@ if (!fs.existsSync(logFileDirectory)) {
const deleteLogFile =(filePath: string) => {
try {
fs.unlinkSync(filePath);
logger.info("Deleted expired log file", { filename: __filename });
logger.info("Deleted expired log file", { filename: path.basename(__filename) });
} catch (error) {
logger.error("Failed to expired log file:", error);
}
@ -52,7 +52,7 @@ const consoleFormat = combine(
message = chalk.white(message);
filename = chalk.white(filename || "unknown")
return `[${level}] (${filename}) ${timestamp}: ${message}`;
return `[${level}] ${timestamp} (${filename}): ${message}`;
})
);

View File

@ -1,10 +1,15 @@
import { Request, Response, NextFunction } from "express";
import { client as bot } from "@bot/bot";
import { getLogger } from "@server/../log";
const logger = getLogger(__filename);
// Todo: update this comment as a jsdoc
// The purpose of this middleware is to attach an object containing cached
// Discord servers to the response, which is accessible in the DOM.
// This is primarily used for rendering servers on the sidebar.
export const attachGuilds = (_request: Request, response: Response, next: NextFunction) => {
logger.debug(`Attaching ${bot.guilds.cache.size} cached guilds to the response locals`);
response.locals.guilds = bot.guilds.cache.map(guild => guild);
next();
}

View File

@ -1,10 +1,17 @@
import { Request, Response, NextFunction } from "express";
import { getLogger } from "@server/../log";
const logger = getLogger(__filename);
// This middleware returns the last segment of the url path.
// It's used to identify which tab to highlight as active on
// the guild view at '/guild/<id>/<page>'
export const guildTabHelper = (request: Request, response: Response, next: NextFunction) => {
const currentPath = request.path.split("/")
response.locals.guildPage = currentPath[currentPath.length - 1]
const guildPage = currentPath[currentPath.length - 1];
logger.debug(`Attaching '${guildPage}' tab helper to response locals`);
response.locals.guildPage = guildPage;
next();
}