You can do something like this:
/**
* This is for logging entrance to a specific route.
*/
static log(req, _res, next) {
const {
body,
query,
params,
method,
originalUrl,
} = req;
let info = `Entered ${method} ${originalUrl} `;
if (Object.keys(body).length) info += `| body: ${JSON.stringify(body)}`;
if (Object.keys(query).length) info += `| query: ${JSON.stringify(query)}`;
if (Object.keys(params).length) info += `| params: ${JSON.stringify(params)}`;
Logger.info(info);
return next();
}
and implement it on the route:
testRoute.get('/test', log, TestController.Test);
You can user if for all POST/PUT/GET/DELETE