ATP Log4JS
A customized logging library for React JS applications.
Features
- Application Logging
- Event Logging
- Error Logging
Installation
npm install qdm-log4js
Usage
Initialize
Initialize logger with User Id and Application Name
import Logger from "qdm-log4js";
let log = new Logger();
log.init("USER_ID", "APPLICATION_NAME");
Application Logging
Application log levels include the standard set: trace, debug, info, warn, error and fatal.
log.trace("Entering cheese testing");
log.debug("Got cheese.");
log.info("Cheese is Comté.");
log.warn("Cheese is quite smelly.");
log.error("Cheese is too ripe!");
log.fatal("Cheese was breeding ground for listeria.");
Sample Output
{
"TimeStamp": "2022-06-17T14:17:27.252Z",
"LogType": "Application",
"ApplicationName": "CLMM",
"LogLevel": "FATAL",
"UserID": "Pxs0362",
"LogMessage": "This is fatal log ",
"Browser": "chrome",
"BrowserVersion": "102.0.0",
"Clientos": "Windows 10",
"IPAddress": "106.203.53.81"
}
Event Logging
//Declare constants of Event Codes; it should match with DB entries
const AddPharmacyLocation = "ADD_PH_LOCN";
const EditPharmacyLocation = "EDIT_PH_LOCN";
// Sample event data
var eventData = {
pharmacyLocation: "Kangar",
phrmacyPincode: "01502",
};
log.event(AddPharmacyLocation, eventData);
log.event(EditPharmacyLocation, eventData);
Sample Output
{
"TimeStamp": "2022-06-17T14:17:25.542Z",
"LogType": "Event",
"ApplicationName": "CLMM",
"UserID": "Pxs0362",
"EventCode": "ADD_PH_LOC",
"EventName": "Add Pharmacy Location",
"EventFunctionGroup": "Pharmacy",
"EventScreen": "Pharmacy",
"EventData": {
"pharmacyLocation": "Kangar",
"phrmacyPincode": "01502"
},
"Browser": "chrome",
"BrowserVersion": "102.0.0",
"Clientos": "Windows 10",
"IPAddress": "106.203.53.81"
}
Error Logging
//Declare constants of Error Codes; it should match with DB entries
const INTERNAL_SERVER_ERROR_CODE = "500";
// Sample error data
var errorData = {
errorMsg = "User Defined Message"
};
log.event(INTERNAL_SERVER_ERROR_CODE, errorData);
Sample Output
{
"TimeStamp": "2022-07-25T06:10:02.735Z",
"LogType": "Error",
"ApplicationName": "REACT",
"ErrorCode": "500",
"ErrorMessage": "Internal Server Error",
"ErrorData": "Optional error JSON Data",
"Browser": "chrome",
"BrowserVersion": "102.0.0",
"Clientos": "Windows 10",
"IPAddress": "106.203.53.81"
}
Configuration (.env)
REACT_APP_GEOLOCATION_DB_URL = "https://geolocation-db.com/json/"
REACT_APP_ARANGO_SERVICE_URL = "http://164.52.210.54:8080"
REACT_APP_ARANGO_DB_NAME = "ATP_Metadata_Dev"
REACT_APP_LOGGER_COLLECTION_NAME = "Logger_Config"
REACT_APP_LOGGER_NIFI_URL = "http://101.53.136.60:9999/api/logging"
REACT_APP_EVENT_COLLECTION_NAME = "clmm_event_catalog"
Arango DB Details
Name | Value |
---|---|
DB Name | ATP_Metadata_DEV |
Logger Collection Name | Logger_Config |
Event Collection Name | clmm_event_catalog |