Skip to main content

ATP Log4J

A customized logging library for Java applications.

Features

  • Application Logging
  • Event Logging
  • Error Logging

JAR Details

JAR Path    : https://github.com/ainqa-platform/qdm-log4j/tree/feature/QDMLog4J
JAR Name : QDMLog4J.jar
Class Name : QdmLogger

Installation

Add the JAR in Java Build path as external JAR.

Usage

Initialize

Initialize logger with User Id and Application Name

import QdmLogger;

QdmLogger logger = new QdmLogger();

logger.init("USER_ID","APPLICATION_NAME", "DATABASE_NAME", "ARANGO_SERVICE_URL", "LOGGER_COLLECTION_NAME","EVENT_COLLECTION_NAME", "LOGGER_NIFI_URL");

Application Logging

Application log levels include the standard set: trace, debug, info, warn, error and fatal.

logger.trace("Entering cheese testing");
logger.debug("Got cheese.");
logger.info("Cheese is Comté.");
logger.warn("Cheese is quite smelly.");
logger.error("Cheese is too ripe!");
logger.fatal("Cheese was breeding ground for listeria.");

Sample Output

{
"TimeStamp": "2022-19-15T12:07:44.376Z",
"LogType": "application",
"ApplicationName": "clmm",
"LogLevel": "trace",
"UserId": "Pxs0362",
"FileName": "App.java",
"FunctionName": "main",
"LineNumber": "25",
"LogMessage": "Trace Error"
}

Event Logging

JSONObject eventData = new JSONObject();

eventData.put("pharmacyLocation", "Kangar");
eventData.put("phrmacyPincode", "01502");

// Event Logs
logger.event(AddPharmacyLocation, eventData)
logger.event(EditPharmacyLocation, eventData)

Sample Output

{
"TimeStamp": "2022-19-15T12:07:47.393Z",
"LogType": "Event",
"ApplicationName": "clmm",
"UserId": "Pxs0362",
"EventName": "Add Pharmacy Location",
"EventFunctionGroup": "Pharmacy",
"EventScreen": "Pharmacy",
"EventData": {
"pharmacyLocation": "Kangar",
"phrmacyPincode": "01502"
}
}

Error Logging

static final int ERROR_CODE = 404;
JSONObject errorData = new JSONObject();

errorData.put("ErrorMsg", "User defined message");

// Event Logs
logger.event(ERROR_CODE, errorData)

Sample Output

{
"TimeStamp": "2022-06-20T00:00:00+05:30",
"LogType": "Error",
"ApplicationName": "clmm",
"UserID": "pxs0362",
"ErrorCode": "404",
"ErrorMessage": "Service URL not recognized",
"ErrorDescription": "Server cannot find the requested resources"
}

Configuration (application.yaml)

logging_api: http://101.53.136.60:9999/api/logging
db_url: http://164.52.210.54:8080
db_name: ATP_Metadata_Dev
collection_name: Logger_Config
event_collection_name: clmm_event_catalog

Arango DB Details

NameValue
DB NameATP_Metadata_DEV
Logger Collection NameLogger_Config
Event Collection Nameclmm_event_catalog