This DHP shared library contains common components for logging/tracing and GDPR compliant logging for other backend microservices.
- The class
Logger
logs messages to the console as JSON messages - The logger supports the following logging operations: info, warn, error, debug, trace
- The logger allows the setting of a correlation id, allowing for correlating "transactions" across different microservice log entries
GDPRLogger exports PII CRUD operation logs to an external datastore for compliance requirements. This module exports a function, getGdprLogger, which returns an instance of GDPRLogger.
The default datastore used is Cloudant, which require following environment variables to be set:
- CLOUDANT_URL : The Cloudant URL found in IBM Cloud service credentials url value
- CLOUDANT_IAM_KEY : The Cloudant IAM key found in IBM Cloud service credentials apikey
To initialize GDPRLogger, place the following code in the middleware where the transaction id is generated, and wrap the return() function.
Session values (transactionId, callerIp, and url) will be sent to the external datastore whenever GDPRLogger.log is called.
The getSession and setSession functions use the cls-hooked library for continuation-local storage, which ensures that the session variables passed to setSession are available (for logging for example) throughout the life of the request. This eliminates the need to pass these values as function parameters throughout the app.
const { getSession, setSession } = require('healthpass-logging-lib/gdpr');
const session = getSession(req, res, logLevel);
session.run(async () => {
setSession(
session,
transactionID,
callerIp,
`/datasubmission${req.originalUrl}`,
);
return next();
});
To invoke the GDPRLogger to export a PII CRUD operation log entry simply call gdprLogger.log passing the holder id and the CRUD operation being performed. Note there is no await on gdprLogger.log in the sample below. This is intentional to insure GDPR logging does not impact the performance of the request.
const { getGdprLogger, CRUD_OPERATION } = require('healthpass-logging-lib/gdpr');
const gdprLogger = getGdprLogger();
gdprLogger.log(holderID, CRUD_OPERATION.CREATE);
npm install
This section lists license details of libraries / dependencies.