@aax/logger v1.0.2
Logger
This library provides a class that logs events to the event logging API via MQ. This library also provides Express routes that can be implemented that will allow a front end to log events via its API.
Note - This is a private package on NPM and you will need to have access to the AAX repository and be logged into NPM within your terminal environment.
🔧 Installation
npm i @aax/logger
🎬 Getting started
The library has 5 static methods that align with the log levels handled by the
Event Logger API. The only level that will be accessible by consumers is info
.
import { Logger, Payload } from "@aax/logger";
const payload: Payload = {
data: {
event: "Joe Smith was added to Team Alpha",
module: "employees",
sector: "teams",
reference: "1234-abcd-1234-abcd",
updatedBy: {
pass: "user from payload here..."
},
snapshot: {
snap: "shot",
eg: "example"
}
}
};
Logger.info(payload);
A Payload
type is exported from the library to be used as a type check for
the payload passed to the method
Payload {
data: {
event: string;
module: string;
sector: string | null;
reference: string;
updatedBy: any;
snapshot: any;
};
};
event
- Friendly string for ease of consumption by end usersmodule
- risks, interdependencies, employees, etc.sector
- Nullable, a specific area within the module, e.g. employees -> availabilityreference
- A reference to the logged event, e.g. risk id,updatedBy
- The JSON payload of the user's token the initiated update,snapshot
- Nullable, a JSON snapshot of the entity state before changes were applied
API
The library exports logRouter
which provide endpoints for frontends to log items into the
universal event log.
Note - Make sure you use the routes after initiating the JWT middleware else the routes will be accessible without authentication.
import logRouter from "@aax/logger/API";
const app = express();
app.use(jwt({...}));
app.use(logRouter); // Adds "/logger" to Express router.
GET
/logger
Returns { status: "ok" }
if routes have been successfully added and are working.
Not necessary to query or use.
POST
/logger
Expects Header Content-Type
of JSON
and same payload as the Logger
class.
// In an Angular service...
const payload = {
"data": {
event: "Joe Smith was added to Team Alpha",
module: "employees",
sector: "teams",
reference: "1234-abcd-1234-abcd",
updatedBy: {
pass: "user from payload here..."
},
snapshot: {
snap: "shot",
eg: "example"
}
},
};
this._http.post('https://this.is.the.api/logger, payload);
4 years ago