DouglasNeuroInformatics / OpenDataCapture

An electronic data capture platform for administering remote and in-person clinical instruments
https://opendatacapture.org/en/
Apache License 2.0
101 stars 11 forks source link

[Feature]: Audit logging #194

Open gdevenyi opened 1 year ago

gdevenyi commented 1 year ago

Audit logging is a feature where the system itself will log, certain actions into the DB in a "aduitlogCollection", we need a library that will allow us to insert logs, which we can place where we need to on the backend.

For example:

joshunrau commented 1 year ago

For this, you should not need any new libraries. I will describe the most straightforward (in my option) way I would solve this, but if you can think of a better solution then by all means go ahead. Perhaps you could create a custom decorator for logging (just something that crossed my mind, probably try the solution below first).

Prior to trying to implement this, please make sure you have read, at minimum, the "overview" sections of the NestJS official documentation.

In the backend code, create a new logging module. For this, you will need to create a new module following the naming conventions (e.g., in the directory api/src/logging, create a logging.service.ts and logging.module.ts. You will also need to implement a new database schema to store these logs. For this, please refer to this documentation. For a simple example of creating and using a schema in our code, see the groups module.

In the source code, identify the areas where the actions Gabe describes are implemented (hint, see the auto generated API docs). In those modules, you will need to import the logging module you created and inject the logging service into the services performing the actions to be logged. Then, you can use methods defined on the logging service for actions to be logged.