[SILO-454] chore: refactor decorator, logger packages (#7618)

* [SILO-454] chore: refactor decorator, logger packages

- add registerControllers function abstracting both rest, ws controllers
- update logger to a simple json based logger

* fix: logger instance and middleware

* fix: type and module resolutions

* fix: lodash type package update

* fix: bypass lint errors in decorators

* chore: format changes

---------

Co-authored-by: sriramveeraghanta <veeraghanta.sriram@gmail.com>
This commit is contained in:
Surya Prashanth 2025-08-29 14:29:16 +05:30 committed by GitHub
parent 489a6e1e94
commit 258d24bf06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 222 additions and 352 deletions

View file

@ -1,23 +1,11 @@
import { Request, Response, NextFunction } from "express";
import { logger } from "./config";
import type { RequestHandler } from "express";
import expressWinston from "express-winston";
import { transports } from "winston";
import { loggerConfig } from "./config";
export const requestLogger = (req: Request, res: Response, next: NextFunction) => {
// Log when the request starts
const startTime = Date.now();
// Log request details
logger.http(`Incoming ${req.method} request to ${req.url} from ${req.ip}`);
// Log request body if present
if (Object.keys(req.body).length > 0) {
logger.debug("Request body:", req.body);
}
// Capture response
res.on("finish", () => {
const duration = Date.now() - startTime;
logger.http(`Completed ${req.method} ${req.url} with status ${res.statusCode} in ${duration}ms`);
});
next();
};
export const loggerMiddleware: RequestHandler = expressWinston.logger({
...loggerConfig,
transports: [new transports.Console()],
msg: "{{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms",
expressFormat: true,
});