aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/main/java/org/onap/policy/common/logging/eelf
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/eelf')
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfo.java (renamed from common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java)21
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java16
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java20
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java4
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/MdcInfo.java (renamed from common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java)12
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java (renamed from common-logging/src/main/java/org/onap/policy/common/logging/eelf/Configuration.java)41
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java421
7 files changed, 201 insertions, 334 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfo.java
index f5ab4c79..6086a642 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfo.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,10 +20,11 @@
package org.onap.policy.common.logging.eelf;
+import com.att.eelf.configuration.Configuration;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-public class DroolsPDPMDCInfo implements MDCInfo {
+public class DroolsPdpMdcInfo implements MdcInfo {
private static ConcurrentHashMap<String, String> mdcMap = new ConcurrentHashMap<>();
@@ -34,19 +35,19 @@ public class DroolsPDPMDCInfo implements MDCInfo {
mdcMap.put(Configuration.MDC_SERVICE_INSTANCE_ID, "Policy.droolsPdp.event");
mdcMap.put(Configuration.MDC_INSTANCE_UUID, "");
mdcMap.put(Configuration.MDC_ALERT_SEVERITY, "");
- mdcMap.put(Configuration.PARTNER_NAME, "N/A");
- mdcMap.put(Configuration.STATUS_CODE, "N/A");
- mdcMap.put(Configuration.RESPONSE_CODE, "N/A");
- mdcMap.put(Configuration.RESPONSE_DESCRIPTION, "N/A");
+ mdcMap.put(OnapConfigProperties.PARTNER_NAME, "N/A");
+ mdcMap.put(OnapConfigProperties.STATUS_CODE, "N/A");
+ mdcMap.put(OnapConfigProperties.RESPONSE_CODE, "N/A");
+ mdcMap.put(OnapConfigProperties.RESPONSE_DESCRIPTION, "N/A");
}
/**
* Get the MMDC Info.
- *
+ *
* @return the instance of ConcurrentHashMap.
*/
@Override
- public ConcurrentMap<String, String> getMDCInfo() {
+ public ConcurrentMap<String, String> getMdcInfo() {
return mdcMap;
}
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
index a8d90ad7..1ed11344 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,10 +21,14 @@
package org.onap.policy.common.logging.eelf;
import java.time.Instant;
+import lombok.Getter;
+import lombok.Setter;
/**
* EventData can be used for logging a rule event.
*/
+@Getter
+@Setter
public class EventData {
private String requestId = null;
@@ -40,7 +44,7 @@ public class EventData {
/**
* Create an instance.
- *
+ *
* @param requestId the request ID
* @param startTime the start time
* @param endTime the end time
@@ -51,11 +55,11 @@ public class EventData {
this.endTime = endTime;
}
- public String getRequestID() {
+ public String getRequestId() {
return requestId;
}
- public void setRequestID(String requestId) {
+ public void setRequestId(String requestId) {
this.requestId = requestId;
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java
index 46401e9e..71476c6a 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -45,23 +45,23 @@ public class EventTrackInfo {
/**
* Returns an instance of EventData associated to this requestID.
- *
- * @param requestID request id
+ *
+ * @param requestId request id
* @return EventData
*/
- public EventData getEventDataByRequestID(String requestID) {
- return eventInfo.get(requestID);
+ public EventData getEventDataByRequestId(String requestId) {
+ return eventInfo.get(requestId);
}
/**
* Stores an EventData object in a ConcurrentHashMap using its requestID as key.
- *
+ *
* @param event event data
*/
public void storeEventData(EventData event) {
if (event != null) {
- String id = event.getRequestID();
+ String id = event.getRequestId();
if (id == null || id.isEmpty()) {
return;
}
@@ -74,7 +74,7 @@ public class EventTrackInfo {
/**
* Removes an EventData object from a ConcurrentHashMap using the eventId as key.
- *
+ *
* @param eventId event id
*/
public void remove(String eventId) {
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java
index 5f97c365..4b5c57a8 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -80,7 +80,7 @@ public class EventTrackInfoHandler extends TimerTask {
}
expiredEvents.add(entry.getKey());
- PolicyLogger.info(className + " add expired event request ID: " + event.getRequestID());
+ PolicyLogger.info(className + " add expired event request ID: " + event.getRequestId());
}
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MdcInfo.java
index f7832271..59b8e8c3 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MdcInfo.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,12 +26,12 @@ import java.util.concurrent.ConcurrentMap;
* Interface needs to be implemented by DroolsPDPMDCInfo.
*/
@FunctionalInterface
-public interface MDCInfo {
+public interface MdcInfo {
/**
* Returns MDC info.
- *
+ *
* @return MDC info
*/
- ConcurrentMap<String, String> getMDCInfo();
+ ConcurrentMap<String, String> getMdcInfo();
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/Configuration.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java
index 0752b188..8d2031db 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/Configuration.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,62 +21,67 @@
package org.onap.policy.common.logging.eelf;
-public interface Configuration extends com.att.eelf.configuration.Configuration {
+public class OnapConfigProperties {
/**
* The Date-time of the start of a transaction.
*/
- String BEGIN_TIME_STAMP = "BeginTimestamp";
+ public static final String BEGIN_TIME_STAMP = "BeginTimestamp";
/**
* The Date-time of the end of transaction.
*/
- String END_TIME_STAMP = "EndTimestamp";
+ public static final String END_TIME_STAMP = "EndTimestamp";
/**
* Externally advertised API invoked by clients of this component.
*/
- String SERVICE_NAME = "ServiceName";
+ public static final String SERVICE_NAME = "ServiceName";
/**
* Client or user invoking the API.
*/
- String PARTNER_NAME = "PartnerName";
+ public static final String PARTNER_NAME = "PartnerName";
- String TARGET_ENTITY = "TargetEntity";
+ public static final String TARGET_ENTITY = "TargetEntity";
- String TARGET_SERVICE_NAME = "TargetServiceName";
+ public static final String TARGET_SERVICE_NAME = "TargetServiceName";
/**
* High level success or failure (COMPLETE or ERROR).
*/
- String STATUS_CODE = "StatusCode";
+ public static final String STATUS_CODE = "StatusCode";
/**
* Application specific response code.
*/
- String RESPONSE_CODE = "ResponseCode";
+ public static final String RESPONSE_CODE = "ResponseCode";
/**
* Human readable description of the application specific response code.
*/
- String RESPONSE_DESCRIPTION = "ResponseDescription";
+ public static final String RESPONSE_DESCRIPTION = "ResponseDescription";
/**
* Externally advertised API invoked by clients of this component.
*/
- String ELAPSED_TIME = "ElapsedTime";
+ public static final String ELAPSED_TIME = "ElapsedTime";
/**
* High level failure (ERROR).
*/
- String ERROR_CATEGORY = "ErrorCategory";
+ public static final String ERROR_CATEGORY = "ErrorCategory";
- String ERROR_CODE = "ErrorCode";
+ public static final String ERROR_CODE = "ErrorCode";
- String ERROR_DESCRIPTION = "ErrorDescription";
+ public static final String ERROR_DESCRIPTION = "ErrorDescription";
- String CLASS_NAME = "ClassName";
+ public static final String CLASS_NAME = "ClassName";
- String SERVER_NAME = "ServerName";
+ public static final String SERVER_NAME = "ServerName";
+
+
+ private OnapConfigProperties() {
+ // do nothing
+ }
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
index 87c4c571..cf0cfb3e 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
@@ -28,24 +28,24 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-import static org.onap.policy.common.logging.eelf.Configuration.BEGIN_TIME_STAMP;
-import static org.onap.policy.common.logging.eelf.Configuration.ELAPSED_TIME;
-import static org.onap.policy.common.logging.eelf.Configuration.END_TIME_STAMP;
-import static org.onap.policy.common.logging.eelf.Configuration.ERROR_CATEGORY;
-import static org.onap.policy.common.logging.eelf.Configuration.ERROR_CODE;
-import static org.onap.policy.common.logging.eelf.Configuration.ERROR_DESCRIPTION;
-import static org.onap.policy.common.logging.eelf.Configuration.PARTNER_NAME;
-import static org.onap.policy.common.logging.eelf.Configuration.RESPONSE_CODE;
-import static org.onap.policy.common.logging.eelf.Configuration.RESPONSE_DESCRIPTION;
-import static org.onap.policy.common.logging.eelf.Configuration.SERVER_NAME;
-import static org.onap.policy.common.logging.eelf.Configuration.STATUS_CODE;
-import static org.onap.policy.common.logging.eelf.Configuration.TARGET_ENTITY;
-import static org.onap.policy.common.logging.eelf.Configuration.TARGET_SERVICE_NAME;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.BEGIN_TIME_STAMP;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.ELAPSED_TIME;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.END_TIME_STAMP;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.ERROR_CATEGORY;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.ERROR_CODE;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.ERROR_DESCRIPTION;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.PARTNER_NAME;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_CODE;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_DESCRIPTION;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.SERVER_NAME;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.STATUS_CODE;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.TARGET_ENTITY;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.TARGET_SERVICE_NAME;
+import static org.onap.policy.common.logging.flexlogger.DisplayUtils.displayErrorMessage;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFLogger.Level;
import com.att.eelf.configuration.EELFManager;
-
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.InetAddress;
@@ -60,7 +60,8 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
-
+import java.util.function.Consumer;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.logging.flexlogger.LoggerType;
import org.slf4j.MDC;
@@ -246,7 +247,7 @@ public class PolicyLogger {
* @param transId the transaction ID
* @return String
*/
- public static String postMDCInfoForEvent(String transId) {
+ public static String postMdcInfoForEvent(String transId) {
MDC.clear();
String transactionId = transId;
@@ -258,7 +259,7 @@ public class PolicyLogger {
if ("DROOLS".equalsIgnoreCase(component)) {
MDC.put(TARGET_ENTITY, "POLICY");
MDC.put(TARGET_SERVICE_NAME, "drools evaluate rule");
- return postMDCInfoForEvent(transactionId, new DroolsPDPMDCInfo());
+ return postMdcInfoForEvent(transactionId, new DroolsPdpMdcInfo());
} else {
// For Xacml
MDC.put(TARGET_ENTITY, "POLICY");
@@ -269,38 +270,11 @@ public class PolicyLogger {
MDC.put(MDC_KEY_REQUEST_ID, transactionId);
MDC.put(MDC_SERVICE_NAME, "Policy.xacmlPdp");
MDC.put(MDC_SERVICE_INSTANCE_ID, "Policy.xacmlPdp.event");
- try {
- MDC.put(MDC_SERVER_FQDN, hostName);
- MDC.put(MDC_SERVER_IP_ADDRESS, hostAddress);
- } catch (Exception e) {
- errorLogger.error(MessageCodes.EXCEPTION_ERROR, e, POLICY_LOGGER);
- }
-
- MDC.put(MDC_INSTANCE_UUID, "");
- MDC.put(MDC_ALERT_SEVERITY, "");
-
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
-
- Instant startTime = Instant.now();
- Instant endTime = Instant.now();
-
- String formatedTime = sdf.format(Date.from(startTime));
- MDC.put(BEGIN_TIME_STAMP, formatedTime);
-
- // set default values for these required fields below, they can be overridden
- formatedTime = sdf.format(Date.from(endTime));
- MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, Long.toString(Duration.between(startTime, endTime).toMillis()));
-
- MDC.put(PARTNER_NAME, "N/A");
-
- MDC.put(STATUS_CODE, COMPLETE_STATUS);
- MDC.put(RESPONSE_CODE, "N/A");
- MDC.put(RESPONSE_DESCRIPTION, "N/A");
+ setMdcHostInfo();
+ seTimeStamps();
return transactionId;
-
}
/**
@@ -310,12 +284,12 @@ public class PolicyLogger {
* @param mdcInfo the MDC info
* @return String
*/
- private static String postMDCInfoForEvent(String transId, MDCInfo mdcInfo) {
+ private static String postMdcInfoForEvent(String transId, MdcInfo mdcInfo) {
MDC.put(MDC_KEY_REQUEST_ID, transId);
- if (mdcInfo != null && mdcInfo.getMDCInfo() != null && !mdcInfo.getMDCInfo().isEmpty()) {
+ if (mdcInfo != null && mdcInfo.getMdcInfo() != null && !mdcInfo.getMdcInfo().isEmpty()) {
- ConcurrentMap<String, String> mdcMap = mdcInfo.getMDCInfo();
+ ConcurrentMap<String, String> mdcMap = mdcInfo.getMdcInfo();
Iterator<String> keyIterator = mdcMap.keySet().iterator();
String key;
@@ -325,24 +299,12 @@ public class PolicyLogger {
}
}
- try {
- MDC.put(MDC_SERVER_FQDN, hostName);
- MDC.put(MDC_SERVER_IP_ADDRESS, hostAddress);
- } catch (Exception e) {
- errorLogger.error(MessageCodes.EXCEPTION_ERROR, e, POLICY_LOGGER);
- }
+ setMdcHostInfo();
+
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
-
- String formatedTime = sdf.format(Date.from(startTime));
- MDC.put(BEGIN_TIME_STAMP, formatedTime);
-
- // set default values for these required fields below, they can be overridden
- formatedTime = sdf.format(Date.from(endTime));
- MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, Long.toString(Duration.between(startTime, endTime).toMillis()));
+ seTimeStamps(startTime, endTime);
return transId;
}
@@ -352,8 +314,17 @@ public class PolicyLogger {
*
* @param eventObject event object
*/
- public static void postMDCInfoForEvent(Object eventObject) {
- postMDCInfoForEvent("" + eventObject);
+ public static void postMdcInfoForEvent(Object eventObject) {
+ postMdcInfoForEvent("" + eventObject);
+ }
+
+ private static void setMdcHostInfo() {
+ try {
+ MDC.put(MDC_SERVER_FQDN, hostName);
+ MDC.put(MDC_SERVER_IP_ADDRESS, hostAddress);
+ } catch (Exception e) {
+ errorLogger.error(MessageCodes.EXCEPTION_ERROR, e, POLICY_LOGGER);
+ }
}
/**
@@ -364,18 +335,10 @@ public class PolicyLogger {
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
-
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- String formatedTime = sdf.format(Date.from(startTime));
- MDC.put(BEGIN_TIME_STAMP, formatedTime);
-
- // set default values for these required fields below, they can be overridden
- formatedTime = sdf.format(Date.from(endTime));
- MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, Long.toString(Duration.between(startTime, endTime).toMillis()));
+ seTimeStamps(startTime, endTime);
MDC.put(PARTNER_NAME, "N/A");
@@ -385,6 +348,18 @@ public class PolicyLogger {
}
+ private static void seTimeStamps(Instant startTime, Instant endTime) {
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
+
+ String formatedTime = sdf.format(Date.from(startTime));
+ MDC.put(BEGIN_TIME_STAMP, formatedTime);
+
+ // set default values for these required fields below, they can be overridden
+ formatedTime = sdf.format(Date.from(endTime));
+ MDC.put(END_TIME_STAMP, formatedTime);
+ MDC.put(ELAPSED_TIME, Long.toString(Duration.between(startTime, endTime).toMillis()));
+ }
+
/**
* Sets transaction Id to MDC.
*
@@ -411,7 +386,7 @@ public class PolicyLogger {
* @param transId the transaction ID
* @return String
*/
- public static String postMDCInfoForTriggeredRule(String transId) {
+ public static String postMdcInfoForTriggeredRule(String transId) {
String transactionId = transId;
@@ -424,12 +399,7 @@ public class PolicyLogger {
MDC.put(MDC_KEY_REQUEST_ID, transactionId);
MDC.put(MDC_SERVICE_NAME, "Policy.droolsPdp");
MDC.put(MDC_SERVICE_INSTANCE_ID, "");
- try {
- MDC.put(MDC_SERVER_FQDN, hostName);
- MDC.put(MDC_SERVER_IP_ADDRESS, hostAddress);
- } catch (Exception e) {
- errorLogger.error(MessageCodes.EXCEPTION_ERROR, e, POLICY_LOGGER);
- }
+ setMdcHostInfo();
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
MDC.put(STATUS_CODE, COMPLETE_STATUS);
@@ -443,9 +413,9 @@ public class PolicyLogger {
*
* @param obj object
*/
- public static void postMDCUUIDForTriggeredRule(Object obj) {
+ public static void postMdcUuidForTriggeredRule(Object obj) {
- postMDCInfoForTriggeredRule("" + obj);
+ postMdcInfoForTriggeredRule("" + obj);
}
@@ -864,13 +834,13 @@ public class PolicyLogger {
public static void recordAuditEventStart(String eventId) {
MDC.put(STATUS_CODE, COMPLETE_STATUS);
- postMDCInfoForEvent(eventId);
+ postMdcInfoForEvent(eventId);
if (eventTracker == null) {
eventTracker = new EventTrackInfo();
}
EventData event = new EventData();
- event.setRequestID(eventId);
+ event.setRequestId(eventId);
event.setStartTime(Instant.now());
eventTracker.storeEventData(event);
MDC.put(MDC_KEY_REQUEST_ID, eventId);
@@ -1002,7 +972,7 @@ public class PolicyLogger {
return;
}
- EventData event = eventTracker.getEventDataByRequestID(eventId);
+ EventData event = eventTracker.getEventDataByRequestId(eventId);
if (event != null) {
Instant endTime = event.getEndTime();
@@ -1030,7 +1000,7 @@ public class PolicyLogger {
return;
}
- EventData event = eventTracker.getEventDataByRequestID(eventId.toString());
+ EventData event = eventTracker.getEventDataByRequestId(eventId.toString());
if (event != null) {
Instant endTime = event.getEndTime();
@@ -1065,27 +1035,18 @@ public class PolicyLogger {
MDC.put(MDC_KEY_REQUEST_ID, eventId);
}
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
-
- String formatedTime = sdf.format(Date.from(startTime));
- MDC.put(BEGIN_TIME_STAMP, formatedTime);
-
- // set default values for these required fields below, they can be overridden
- formatedTime = sdf.format(Date.from(endTime));
- MDC.put(END_TIME_STAMP, formatedTime);
+ seTimeStamps(startTime, endTime);
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
long ns = Duration.between(startTime, endTime).toMillis();
- MDC.put(ELAPSED_TIME, Long.toString(ns));
-
auditLogger.info(MessageCodes.RULE_AUDIT_START_END_INFO, MDC.get(MDC_SERVICE_NAME), rule, startTime.toString(),
endTime.toString(), Long.toString(ns), policyVersion);
// --- remove the record from the concurrentHashMap
- if (eventTracker != null && eventTracker.getEventDataByRequestID(eventId) != null) {
+ if (eventTracker != null && eventTracker.getEventDataByRequestId(eventId) != null) {
eventTracker.remove(eventId);
debugLogger.info("eventTracker.remove(" + eventId + ")");
@@ -1258,227 +1219,124 @@ public class PolicyLogger {
*/
public static LoggerType init(Properties properties) {
- Properties loggerProperties;
- if (properties != null) {
- loggerProperties = properties;
- } else {
- System.err.println("PolicyLogger cannot find its configuration - continue");
- loggerProperties = new Properties();
- }
-
- LoggerType loggerType = LoggerType.EELF;
+ Properties loggerProperties = getLoggerProperties(properties);
// fetch and verify definitions of some properties
try {
+ setOverrideLogbackLevels(loggerProperties);
- final int timerDelayTimeProp =
- Integer.parseInt(loggerProperties.getProperty("timer.delay.time", Integer.toString(1000)));
- final int checkIntervalProp =
- Integer.parseInt(loggerProperties.getProperty("check.interval", Integer.toString(30000)));
- final int expiredDateProp =
- Integer.parseInt(loggerProperties.getProperty("event.expired.time", Integer.toString(86400)));
- final int concurrentHashMapLimitProp =
- Integer.parseInt(loggerProperties.getProperty("concurrentHashMap.limit", Integer.toString(5000)));
- final int stopCheckPointProp =
- Integer.parseInt(loggerProperties.getProperty("stop.check.point", Integer.toString(2500)));
- final String loggerTypeProp = loggerProperties.getProperty("logger.type", loggerType.toString());
-
- final String debugLevelProp = loggerProperties.getProperty("debugLogger.level", "INFO");
- final String metricsLevelProp = loggerProperties.getProperty("metricsLogger.level", "ON");
- final String auditLevelProp = loggerProperties.getProperty("audit.level", "ON");
- final String errorLevelProp = loggerProperties.getProperty("error.level", "ON");
- component = loggerProperties.getProperty("policy.component", "DROOLS");
- final String overrideLogbackLevel = loggerProperties.getProperty("override.logback.level.setup");
-
- if (overrideLogbackLevel != null && !overrideLogbackLevel.isEmpty()) {
- if ("TRUE".equalsIgnoreCase(overrideLogbackLevel)) {
- isOverrideLogbackLevel = true;
- } else {
- isOverrideLogbackLevel = false;
- }
- }
-
-
- if (debugLevelProp != null && !debugLevelProp.isEmpty()) {
-
- PolicyLogger.setDebugLevel(Level.valueOf(debugLevelProp));
+ setLoggerLevel(loggerProperties, "debugLogger.level", "INFO", PolicyLogger::setDebugLevel);
- }
- // Only check if it is to turn off or not
- if (errorLevelProp != null && errorLevelProp.equalsIgnoreCase(Level.OFF.toString())) {
-
- PolicyLogger.setErrorLevel(Level.valueOf(errorLevelProp));
+ // Only check if it is to turn on or off
+ setLoggerOnOff(loggerProperties, "metricsLogger.level", PolicyLogger::setMetricsLevel);
+ setLoggerOnOff(loggerProperties, "audit.level", PolicyLogger::setAuditLevel);
+ setLoggerOnOff(loggerProperties, "error.level", PolicyLogger::setErrorLevel);
- }
- // Only check if it is to turn off or not
- if (metricsLevelProp != null && metricsLevelProp.equalsIgnoreCase(Level.OFF.toString())) {
-
- PolicyLogger.setMetricsLevel(Level.valueOf(metricsLevelProp));
-
- }
- // Only check if it is to turn off or not
- if (auditLevelProp != null && auditLevelProp.equalsIgnoreCase(Level.OFF.toString())) {
-
- PolicyLogger.setAuditLevel(Level.valueOf(auditLevelProp));
-
- }
-
- if (isOverrideLogbackLevel) {
-
- debugLogger.setLevel(debugLevel);
- metricsLogger.setLevel(metricsLevel);
- auditLogger.setLevel(auditLevel);
- errorLogger.setLevel(errorLevel);
-
- }
isEventTrackerRunning = false;
- debugLogger.info("timerDelayTime value: " + timerDelayTimeProp);
-
- debugLogger.info("checkInterval value: " + checkIntervalProp);
-
- debugLogger.info("expiredDate value: " + expiredDateProp);
-
- debugLogger.info("concurrentHashMapLimit value: " + concurrentHashMapLimitProp);
-
- debugLogger.info("loggerType value: " + loggerTypeProp);
-
- debugLogger.info("debugLogger level: " + debugLevelProp);
+ timerDelayTime = getIntProp(loggerProperties, "timer.delay.time", timerDelayTime);
+ checkInterval = getIntProp(loggerProperties, "check.interval", checkInterval);
+ expiredTime = getIntProp(loggerProperties, "event.expired.time", expiredTime);
+ concurrentHashMapLimit = getIntProp(loggerProperties, "concurrentHashMap.limit", concurrentHashMapLimit);
+ stopCheckPoint = getIntProp(loggerProperties, "stop.check.point", stopCheckPoint);
+ component = loggerProperties.getProperty("policy.component", "DROOLS");
debugLogger.info("component: " + component);
- if (timerDelayTimeProp > 0) {
-
- timerDelayTime = timerDelayTimeProp;
-
- } else {
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION,
- ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
-
- }
- errorLogger.error("failed to get the timer.delay.time, so use its default value: " + timerDelayTime);
- }
+ return detmLoggerType(loggerProperties);
- if (checkIntervalProp > 0) {
+ } catch (Exception e) {
+ MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- checkInterval = checkIntervalProp;
+ if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
- } else {
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION,
- ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
-
- }
- errorLogger.error("failed to get the check.interval, so use its default value: " + checkInterval);
}
+ errorLogger.error("failed to get the policyLogger.properties, so use their default values", e);
- if (expiredDateProp > 0) {
-
- expiredTime = expiredDateProp;
-
- } else {
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
-
- if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION,
- ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
-
- }
- errorLogger.error("failed to get the event.expired.time, so use its default value: " + expiredTime);
- }
+ return LoggerType.EELF;
+ }
- if (concurrentHashMapLimitProp > 0) {
+ }
- concurrentHashMapLimit = concurrentHashMapLimitProp;
+ private static int getIntProp(Properties properties, String propName, int defaultValue) {
+ final int propValue = Integer.parseInt(properties.getProperty(propName, String.valueOf(defaultValue)));
- } else {
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION,
- ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
-
- }
- errorLogger.error("failed to get the concurrentHashMap.limit, so use its default value: "
- + concurrentHashMapLimit);
- }
+ debugLogger.info(propName + " value: " + propValue);
- if (stopCheckPointProp > 0) {
+ if (propValue > 0) {
+ return propValue;
- stopCheckPoint = stopCheckPointProp;
+ } else {
+ MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
+ if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION,
+ ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
- } else {
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION,
- ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
-
- }
- errorLogger.error("failed to get the stop.check.point, so use its default value: " + stopCheckPoint);
}
+ errorLogger.error("failed to get the " + propName + ", so use its default value: " + defaultValue);
+ return defaultValue;
+ }
+ }
- if (loggerTypeProp != null) {
-
- if ("EELF".equalsIgnoreCase(loggerTypeProp)) {
-
- loggerType = LoggerType.EELF;
-
- } else if ("LOG4J".equalsIgnoreCase(loggerTypeProp)) {
-
- loggerType = LoggerType.LOG4J;
-
- } else if ("SYSTEMOUT".equalsIgnoreCase(loggerTypeProp)) {
-
- loggerType = LoggerType.SYSTEMOUT;
+ private static Properties getLoggerProperties(Properties properties) {
+ if (properties != null) {
+ return properties;
+ } else {
+ displayErrorMessage("PolicyLogger cannot find its configuration - continue");
+ return new Properties();
+ }
+ }
- }
+ private static void setLoggerLevel(Properties properties, String propName, String defaultValue,
+ Consumer<String> setter) {
- }
+ final String propValue = properties.getProperty(propName, defaultValue);
- if (debugLevelProp != null && !debugLevelProp.isEmpty()) {
+ if (!StringUtils.isBlank(propValue)) {
+ debugLogger.info(propName + " level: " + propValue);
+ }
- debugLevel = Level.valueOf(debugLevelProp);
+ setter.accept(propValue);
+ }
- }
- // Only check if it is to turn off or not
- if (errorLevelProp != null && errorLevelProp.equalsIgnoreCase(Level.OFF.toString())) {
+ private static void setLoggerOnOff(Properties properties, String propName, Consumer<String> setter) {
+ final String propValue = properties.getProperty(propName, "ON");
- errorLevel = Level.valueOf(errorLevelProp);
+ if (Level.OFF.toString().equalsIgnoreCase(propValue)) {
+ debugLogger.info(propName + " level: " + propValue);
+ }
- }
- // Only check if it is to turn off or not
- if (metricsLevelProp != null && metricsLevelProp.equalsIgnoreCase(Level.OFF.toString())) {
+ setter.accept(propValue);
+ }
- metricsLevel = Level.valueOf(metricsLevelProp);
+ private static void setOverrideLogbackLevels(Properties loggerProperties) {
+ final String overrideLogbackLevel = loggerProperties.getProperty("override.logback.level.setup");
- }
- // Only check if it is to turn off or not
- if (auditLevelProp != null && auditLevelProp.equalsIgnoreCase(Level.OFF.toString())) {
+ if (!StringUtils.isBlank(overrideLogbackLevel)) {
+ isOverrideLogbackLevel = "TRUE".equalsIgnoreCase(overrideLogbackLevel);
+ }
+ }
- auditLevel = Level.valueOf(auditLevelProp);
+ private static LoggerType detmLoggerType(Properties loggerProperties) {
+ final String loggerTypeProp = loggerProperties.getProperty("logger.type", LoggerType.EELF.toString());
+ debugLogger.info("loggerType value: " + loggerTypeProp);
- }
+ switch (loggerTypeProp.toUpperCase()) {
+ case "EELF":
+ return LoggerType.EELF;
- } catch (Exception e) {
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
+ case "LOG4J":
+ return LoggerType.LOG4J;
- if (ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ case "SYSTEMOUT":
+ return LoggerType.SYSTEMOUT;
- }
- errorLogger.error("failed to get the policyLogger.properties, so use their default values", e);
+ default:
+ return LoggerType.EELF;
}
-
- return loggerType;
-
}
@@ -1505,5 +1363,4 @@ public class PolicyLogger {
public static void setServerInfo(String serverHost, String serverPort) {
MDC.put(SERVER_NAME, serverHost + ":" + serverPort);
}
-
}