Open mattsahn opened 1 year ago
export const protect = asyncHandler(async (req, res, next) => {
const user = await checkTokenAndExtractUser(req, res);
res.locals.user = user;
logger.info(`(${user.fields.Username}) ${req.method} ${req.originalUrl}`);
next();
});
Adding this snippet to the auth middleware allows for logging to be done easily on all the api calls. The only issue is other logs within the functions dont have the username so I am finding a fix for that.
Our current logs show timestamp, type of request, and URL details, but do not show which logged-in user made the request. Our intention is to move towards using actual users for each user rather than a single, shared admin user. At that point, it's important for logs to show who each user is that is interacting with the server. This issue is to add username to the standard log output for all requests. Format could be this:
[2023-09-08T21:42:48.173Z] INFO: (grassrootsadmin) PATCH /api/volunteers/confirm/recDiz3Sk4kBOnrP6
Existing logs: