#174: Add User Action Logging#204
Conversation
| router.use(json()); | ||
|
|
||
| router.use(authMiddleware(authConfig)); | ||
| router.use(actionLoggerMiddleware({ enabled: authConfig.enabled }, baseDependencies.logger)); |
There was a problem hiding this comment.
having actionLoggerMiddleware after the authMiddleware won't be called on an unauthorized request.
There was a problem hiding this comment.
In the case of clinical there's already an implementation of a request logger, which I think will duplicate some information..
| // Capture request context after validation (when params/body/query are populated) | ||
| // Needed for logging and for error middleware to access request context | ||
| res.locals.requestContext = { | ||
| method: req.method, | ||
| path: req.originalUrl || req.path, | ||
| params: req.params, | ||
| query: req.query, | ||
| ...(req.method !== 'GET' && req.body ? { body: req.body } : {}), | ||
| }; |
There was a problem hiding this comment.
Create a locals for requestContext in the requestValidation. This ensure that the mapped params/query/body is passed into the errorHandler middleware.
| features?: FeaturesConfig; | ||
| idService: IdServiceConfig; | ||
| logger: LoggerConfig; | ||
| disableLogger?: boolean; |
There was a problem hiding this comment.
this variable name could be a little bit confusing, thinking that this enables a router level middleware maybe routerLoggerEnabled could be an option? up to you.
There was a problem hiding this comment.
can it also be included in the LoggerConfig properties
| export const shouldLogRoute = (path: string): boolean => { | ||
| const excludedPaths = ['/health', '/ping', '/api-docs']; | ||
| return !excludedPaths.some((excluded) => path.startsWith(excluded)); | ||
| }; |
There was a problem hiding this comment.
this function seems usefull, but is not being used, should be removed?
| features: configData.features, | ||
| idService: configData.idService, | ||
| logger: getLogger(configData.logger), | ||
| disableLogger: configData.disableLogger || false, |
There was a problem hiding this comment.
a ?? could be more appropiate for this.
Summary
Add's
actionLogger.tsmiddleware that will intercept responses from endpoints and log the result returned from lyrics business logic.Issues
Description of Changes
Package Data-Provider
Add
actionLogger.ts,actionloggerUtils.tsactionLogger contains middleware that will intercept responses from lyric and log who made the request and what the result was
actionLoggerUtils contains helper function, types, formatting functions and parsing options for the logging string
add
actionLoggerMiddlewareto all endpoints in:auditRouter.tscategoryRouter.tsdictionaryRouter.tssubmissionRouter.tssubmittedDataRouter.tsvalidationRouter.tsSpecial Instructions
Before running these changes, you will need to:
Readiness Checklist
.env.schemafile and documented in the README