Skip to content

#174: Add User Action Logging#204

Open
JamesTLopez wants to merge 20 commits into
mainfrom
feat/174-lyric-logging
Open

#174: Add User Action Logging#204
JamesTLopez wants to merge 20 commits into
mainfrom
feat/174-lyric-logging

Conversation

@JamesTLopez

@JamesTLopez JamesTLopez commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Add's actionLogger.ts middleware 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.ts

  • actionLogger 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 actionLoggerMiddleware to all endpoints in:

    • auditRouter.ts
    • categoryRouter.ts
    • dictionaryRouter.ts
    • submissionRouter.ts
    • submittedDataRouter.ts
    • validationRouter.ts

Special Instructions

Before running these changes, you will need to:

pnpm i && pnpm build:all

Readiness Checklist

  • Self Review
    • I have performed a self review of code
    • I have run the application locally and manually tested the feature
    • I have checked all updates to correct typos and misspellings
  • Formatting
    • Code follows the project style guide
    • Autmated code formatters (ie. Prettier) have been run
  • Local Testing
    • Successfully built all packages locally
    • Successfully ran all test suites, all unit and integration tests pass
  • Updated Tests
    • Unit and integration tests have been added that describe the bug that was fixed or the features that were added
  • Documentation
    • All new environment variables added to .env.schema file and documented in the README
    • All changes to server HTTP endpoints have open-api documentation
    • All new functions exported from their module have TSDoc comment documentation

Comment thread packages/data-provider/src/utils/actionLoggerUtils.ts
router.use(json());

router.use(authMiddleware(authConfig));
router.use(actionLoggerMiddleware({ enabled: authConfig.enabled }, baseDependencies.logger));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having actionLoggerMiddleware after the authMiddleware won't be called on an unauthorized request.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of clinical there's already an implementation of a request logger, which I think will duplicate some information..

Comment on lines +50 to +58
// 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 } : {}),
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a locals for requestContext in the requestValidation. This ensure that the mapped params/query/body is passed into the errorHandler middleware.

@JamesTLopez JamesTLopez requested a review from leoraba June 14, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants