aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src/main/java/org/openecomp/policy/common/logging/eelf')
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java91
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/DroolsPDPMDCInfo.java53
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/ErrorCodeMap.java112
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventData.java93
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfo.java90
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfoHandler.java109
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MDCInfo.java35
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MessageCodes.java163
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java1438
9 files changed, 2184 insertions, 0 deletions
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
new file mode 100644
index 00000000..a2a0b783
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+
+public interface Configuration extends com.att.eelf.configuration.Configuration{
+
+ /**
+ * The Date-time of the start of a transaction
+ */
+ public String BEGIN_TIME_STAMP = "BeginTimestamp";
+
+ /**
+ * The Date-time of the end of transaction
+ */
+ public String END_TIME_STAMP = "EndTimestamp";
+
+ /**
+ * Externally advertised API invoked by clients of this component
+ */
+ public String SERVICE_NAME = "ServiceName";
+
+ /**
+ * Client or user invoking the API
+ */
+ public String PARTNER_NAME = "PartnerName";
+
+ /**
+ * High level success or failure (COMPLETE or ERROR)
+ */
+ public String STATUS_CODE = "StatusCode";
+
+ /**
+ * Application specific response code
+ */
+ public String RESPONSE_CODE = "ResponseCode";
+
+ /**
+ * Human readable description of the application specific response code
+ */
+ public String RESPONSE_DESCRIPTION = "ResponseDescription";
+
+ /**
+ * Externally advertised API invoked by clients of this component
+ */
+ public String ELAPSED_TIME = "ElapsedTime";
+
+ /**
+ * High level failure (ERROR)
+ */
+ public String ERROR_CATEGORY = "ErrorCategory";
+
+ /**
+ * Error Code
+ */
+ public String ERROR_CODE = "ErrorCode";
+
+ /**
+ * Error Description
+ */
+ public String ERROR_DESCRIPTION = "ErrorDesciption";
+
+ /**
+ * Class name
+ */
+ public String CLASS_NAME = "ClassName";
+
+ /**
+ * Server name
+ */
+ public String SERVER_NAME = "ServerName";
+
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/DroolsPDPMDCInfo.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/DroolsPDPMDCInfo.java
new file mode 100644
index 00000000..ad502475
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/DroolsPDPMDCInfo.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+public class DroolsPDPMDCInfo implements MDCInfo{
+
+ private static ConcurrentHashMap<String, String> mdcMap = new ConcurrentHashMap<String, String>();
+
+ static {
+
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.MDC_REMOTE_HOST, "");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.MDC_SERVICE_NAME, "Policy.droolsPdp");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.MDC_SERVICE_INSTANCE_ID, "Policy.droolsPdp.event");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.MDC_INSTANCE_UUID, "");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.MDC_ALERT_SEVERITY, "");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.PARTNER_NAME, "N/A");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.STATUS_CODE, "N/A");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.RESPONSE_CODE, "N/A");
+ mdcMap.put(org.openecomp.policy.common.logging.eelf.Configuration.RESPONSE_DESCRIPTION, "N/A");
+
+ }
+
+ @Override
+ /**
+ * @return the instance of ConcurrentHashMap
+ */
+ public ConcurrentHashMap<String, String> getMDCInfo() {
+
+ return mdcMap;
+ }
+
+
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/ErrorCodeMap.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/ErrorCodeMap.java
new file mode 100644
index 00000000..4e4457d0
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/ErrorCodeMap.java
@@ -0,0 +1,112 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * ErrorCodeMap contains a HashMap of ErrorCodeInfo (error code and error description)
+ *
+ */
+public class ErrorCodeMap {
+
+
+ public static HashMap<MessageCodes, ErrorCodeInfo> hm = new HashMap();
+
+ private static String ERROR_PERMISSIONS = "POLICY-100E";
+ private static String ERROR_PERMISSIONS_DESCRIPTION = "This is a Permissions Error. Please check the error message for detail information";
+
+ private static String ERROR_SCHEMA_INVALID = "POLICY-400E";
+ private static String ERROR_SCHEMA_INVALID_DESCRIPTION = "This is an Invalid Schema Error. Please check the error message for detail information";
+
+ private static String UPDATE_ERROR = "POLICY-502E";
+ private static String UPDATE_ERROR_DESCRIPTION = "This is an updating error. Please check the error message for detail information";
+
+ private static String EXCEPTION_ERROR_CODE = "POLICY-503E";
+ private static String EXCEPTION_ERROR_DESCRIPTION = "This is an exception error message during the process. Please check the error message for detail information";
+
+ private static String MISS_PROPERTY_ERROR = "POLICY-504E";
+ private static String MISS_PROPERTY_ERROR_DESCRIPTION = "This is an error of missing properties. Please check the error message for detail information";
+
+ private static String GENERAL_ERROR_CODE = "POLICY-515E";
+ private static String GENERAL_ERROR_DESCRIPTION = "This is a general error message during the process. Please check the error message for detail information";
+
+ private static String ERROR_SYSTEM_ERROR = "POLICY-516E";
+ private static String ERROR_SYSTEM_ERROR_DESCRIPTION = "This is a System Error. Please check the error message for detail information";
+
+ private static String ERROR_DATA_ISSUE = "POLICY-517E";
+ private static String ERROR_DATA_ISSUE_DESCRIPTION = "This is a Data Issue Error. Please check the error message for detail information";
+
+ private static String ERROR_PROCESS_FLOW = "POLICY-518E";
+ private static String ERROR_PROCESS_FLOW_DESCRIPTION = "This is a Process Flow Error. Please check the error message for detail information";
+
+ private static String ERROR_UNKNOWN = "POLICY-519E";
+ private static String ERROR_UNKNOWN_DESCRIPTION = "This is an Unknown Error. Please check the error message for detail information";
+
+ private static String ERROR_AUDIT = "POLICY-520E";
+ private static String ERROR_AUDIT_DESCRIPTION = "This is an audit Error. Please check the error message for detail information";
+
+ static {
+ hm.put(MessageCodes.EXCEPTION_ERROR, new ErrorCodeInfo(EXCEPTION_ERROR_CODE, EXCEPTION_ERROR_DESCRIPTION));
+ hm.put(MessageCodes.GENERAL_ERROR, new ErrorCodeInfo(GENERAL_ERROR_CODE, GENERAL_ERROR_DESCRIPTION));
+ hm.put(MessageCodes.MISS_PROPERTY_ERROR, new ErrorCodeInfo(MISS_PROPERTY_ERROR, MISS_PROPERTY_ERROR_DESCRIPTION));
+ hm.put(MessageCodes.UPDATE_ERROR, new ErrorCodeInfo(UPDATE_ERROR, UPDATE_ERROR_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_SYSTEM_ERROR, new ErrorCodeInfo(ERROR_SYSTEM_ERROR, ERROR_SYSTEM_ERROR_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_DATA_ISSUE, new ErrorCodeInfo(ERROR_DATA_ISSUE, ERROR_DATA_ISSUE_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_PERMISSIONS, new ErrorCodeInfo(ERROR_PERMISSIONS, ERROR_PERMISSIONS_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_DATA_ISSUE, new ErrorCodeInfo(ERROR_DATA_ISSUE, ERROR_DATA_ISSUE_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_PROCESS_FLOW, new ErrorCodeInfo(ERROR_PROCESS_FLOW, ERROR_PROCESS_FLOW_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_SCHEMA_INVALID, new ErrorCodeInfo(ERROR_SCHEMA_INVALID, ERROR_SCHEMA_INVALID_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_UNKNOWN, new ErrorCodeInfo(ERROR_UNKNOWN, ERROR_UNKNOWN_DESCRIPTION));
+ hm.put(MessageCodes.ERROR_AUDIT, new ErrorCodeInfo(ERROR_AUDIT, ERROR_AUDIT_DESCRIPTION));
+ }
+
+ static class ErrorCodeInfo {
+
+ private String errorCode;
+ private String errorDesc;
+
+ public ErrorCodeInfo(String errorCode, String errorDesc){
+ this.errorCode = errorCode;
+ this.errorDesc = errorDesc;
+ }
+
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(String errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorDesc() {
+ return errorDesc;
+ }
+
+ public void setErrorDesc(String errorDesc) {
+ this.errorDesc = errorDesc;
+ }
+
+ }
+
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventData.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventData.java
new file mode 100644
index 00000000..549651fb
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventData.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import java.time.Instant;
+
+import javax.swing.text.html.parser.Entity;
+
+/**
+ *
+ * EventData can be used for logging a rule event.
+ *
+ */
+public class EventData {
+
+ private String requestID = null;
+ private Instant startTime = null;
+ private Instant endTime = null;
+
+ public EventData() {
+
+ }
+
+ public EventData(String requestID, Instant startTime, Instant endTime) {
+
+ this.requestID = requestID;
+ this.startTime = startTime;
+ this.endTime = endTime;
+ }
+
+ public String getRequestID() {
+ return requestID;
+ }
+
+ public void setRequestID(String requestID) {
+ this.requestID = requestID;
+ }
+
+ public Instant getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(Instant startTime) {
+ this.startTime = startTime;
+ }
+
+ public Instant getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(Instant endTime) {
+ this.endTime = endTime;
+ }
+
+ public String toString(){
+ return requestID + " Starting Time : " + this.startTime + " Ending Time : " + this.endTime;
+ }
+ @Override
+ public int hashCode(){
+ final int prime =31;
+ int result =1;
+ result = prime * result +((requestID == null) ? 0: requestID.hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj){
+
+ String requestId = (String) obj;
+ if(requestID != null && requestID.equals(requestId)){
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfo.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfo.java
new file mode 100644
index 00000000..c6ed63d4
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfo.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openecomp.policy.common.logging.flexlogger.PropertyUtil;
+
+/**
+ *
+ * EventTrackInfo contains a ConcurrentHashMap of EventData
+ *
+ */
+public class EventTrackInfo {
+
+ private ConcurrentHashMap<String, EventData> eventInfo = null;
+
+ public EventTrackInfo() {
+ /*
+ * An initial capacity of 16 ensures the number of elements before resizing happens
+ * Load factor of 0,9 ensures a dense packaging inside ConcurrentHashMap which will optimize memory use
+ * ConcurencyLevel set to 1 will ensure that only one shard is created and maintained
+ */
+ eventInfo = new ConcurrentHashMap<String, EventData>(16, 0.9f, 1);
+ }
+
+ /**
+ * Returns an instance of EventData associated to this requestID
+ * @param requestID
+ * @return EventData
+ */
+ public EventData getEventDataByRequestID(String requestID){
+ return eventInfo.get(requestID);
+ }
+
+ /**
+ * Stores an EventData object in a ConcurrentHashMap using its requestID as key.
+ * @param event
+ */
+ public void storeEventData(EventData event){
+
+ if(event == null || event.getRequestID() == null || event.getRequestID().isEmpty()){
+ return;
+ }
+ //in case override the start time, check the original event was already stored or not
+ if(!eventInfo.containsKey(event.getRequestID())){
+ eventInfo.put(event.getRequestID(), event);
+ }
+ }
+
+ /**
+ * Removes an EventData object from a ConcurrentHashMap using the eventId as key.
+ * @param eventId
+ */
+ public void remove(String eventId){
+ if(eventInfo != null){
+ eventInfo.remove(eventId);
+ }
+ }
+
+ /**
+ * Returns a ConcurrentHashMap of EventData
+ */
+ public ConcurrentHashMap<String, EventData> getEventInfo() {
+ return eventInfo;
+ }
+
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfoHandler.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfoHandler.java
new file mode 100644
index 00000000..a947ed01
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/EventTrackInfoHandler.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ *
+ * EventTrackInfoHandler is the handler of clean up all expired event objcts
+ *
+ */
+public class EventTrackInfoHandler extends TimerTask {
+
+ String className = this.getClass().getSimpleName();
+
+ @Override
+ public void run() {
+
+ PolicyLogger.info(className
+ + " Release expired event records start...");
+
+ CleanUp();
+
+ PolicyLogger.info(className + " Release expired event records done");
+ }
+
+ /**
+ * Removes all expired event objects from the ConcurrentHashMap of EventData
+ */
+ private void CleanUp() {
+
+ if (PolicyLogger.getEventTracker() == null
+ || PolicyLogger.getEventTracker().getEventInfo() == null
+ || PolicyLogger.getEventTracker().getEventInfo().isEmpty()) {
+ return;
+ }
+
+ Instant startTime = null;
+ long ns = 0;
+
+ ArrayList<String> expiredEvents = null;
+
+ for (String key: PolicyLogger.getEventTracker().getEventInfo().keySet()) {
+ EventData event = PolicyLogger.getEventTracker().getEventInfo().get(key);
+ startTime = event.getStartTime();
+ ns = Duration.between(startTime, Instant.now()).getSeconds();
+
+ PolicyLogger.info(className
+ + " duration time : " + ns);
+
+ PolicyLogger.info(className
+ + " PolicyLogger.EXPIRED_TIME : " + PolicyLogger.EXPIRED_TIME);
+
+ // if longer than EXPIRED_TIME, remove the object
+
+ if (ns > PolicyLogger.EXPIRED_TIME){
+ if (expiredEvents == null) {
+ expiredEvents = new ArrayList<String>();
+ }
+ expiredEvents.add(key);
+
+ PolicyLogger.info(className
+ + " add expired event request ID: "
+ + event.getRequestID());
+ }
+ }
+
+ synchronized (PolicyLogger.getEventTracker().getEventInfo()) {
+ if (expiredEvents != null) {
+ for (String expiredKey : expiredEvents) {
+ PolicyLogger.getEventTracker().getEventInfo()
+ .remove(expiredKey);
+ System.out.println(className
+ + " removed expired event request ID: "
+ + expiredKey);
+ PolicyLogger.info(className
+ + " removed expired event request ID: "
+ + expiredKey);
+ }
+ }
+
+ }
+
+ }
+
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MDCInfo.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MDCInfo.java
new file mode 100644
index 00000000..6b5e395f
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MDCInfo.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ *
+ * Interface needs to be implemented by DroolsPDPMDCInfo
+ *
+ */
+
+public interface MDCInfo {
+
+ public ConcurrentHashMap<String, String> getMDCInfo();
+
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MessageCodes.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MessageCodes.java
new file mode 100644
index 00000000..6f1437eb
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/MessageCodes.java
@@ -0,0 +1,163 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import com.att.eelf.i18n.EELFResolvableErrorEnum;
+import com.att.eelf.i18n.EELFResourceManager;
+
+/**
+ *
+ * MessageCodes contains all the messagge codes for EELF logging messages
+ *
+ */
+public enum MessageCodes implements EELFResolvableErrorEnum {
+ // Below is a list of Error Messages taken from com.att.research.xacml.api XACMLErrorConstants
+ // found under: policy-engine\XACML\src\main\java\com\att\research\xacml\api\XACMLErrorConstants.java
+
+ ERROR_PERMISSIONS,
+
+ ERROR_SYSTEM_ERROR,
+
+ ERROR_DATA_ISSUE,
+
+ ERROR_SCHEMA_INVALID,
+
+ ERROR_PROCESS_FLOW,
+
+ ERROR_UNKNOWN,
+
+ ERROR_AUDIT,
+
+ // Above is a list of Error Messages taken from com.att.research.xacml.api XACMLErrorConstants
+ // found under: policy-engine\XACML\src\main\java\com\att\research\xacml\api\XACMLErrorConstants.java
+
+ //----------------------5000-5099 Business/Flow Processing Related --------------------/
+
+ BAD_TYPE_WARNING,
+
+ GENERAL_INFO,
+
+ GENERAL_WARNING,
+
+ MISS_PROPERTY_ERROR,
+
+ EXCEPTION_ERROR,
+
+ MISS_PROPERTY_INFO,
+
+ RULE_AUDIT_EXEC_INFO,
+
+ RULE_AUDIT_BEGIN_INFO,
+
+ RULE_AUDIT_END_INFO,
+
+ RULE_AUDIT_START_END_INFO,
+
+ RULE_METRICS_INFO,
+
+ UEB_AUDIT_EXEC_INFO,
+
+ UEB_AUDIT_BEGIN_INFO,
+
+ UEB_AUDIT_END_INFO,
+
+ UPDATE_ERROR,
+
+ GENERAL_ERROR,
+
+ //----------------------New enums should be added above this line ------------------------------------------------------------------/
+
+ //--------------------- The enums below are old code. They should not be used since 1607 release and eventually will be removed -----/
+ /**
+ * Application message which requires no arguments
+ */
+ MESSAGE_SAMPLE_NOARGS,
+
+ /**
+ * Application message which requires one argument {0}
+ */
+ MESSAGE_SAMPLE_ONEARGUMENT,
+
+ /**
+ * Audit message which requires one argument {0}
+ */
+ AUDIT_MESSAGE_ONEARGUMENT,
+
+ /**
+ * Error message which requires one argument {0}
+ */
+ ERROR_MESSAGE_ONEARGUMENT,
+
+ /**
+ * Metrics message which requires one argument {0}
+ */
+ METRICS_MESSAGE_ONEARGUMENT,
+
+ /**
+ * Debug message which requires one argument {0}
+ */
+ DEBUG_MESSAGE_ONEARGUMENT,
+
+ /**
+ * Application message which requires two argument {0} and another argument {1}
+ */
+ MESSAGE_SAMPLE_TWOARGUMENTS,
+
+ /**
+ * Sample error exception
+ */
+ MESSAGE_SAMPLE_EXCEPTION,
+
+ /**
+ * Sample warning message
+ */
+ MESSAGE_WARNING_SAMPLE,
+
+ /**
+ * Sample exception in method {0}
+ */
+ MESSAGE_SAMPLE_EXCEPTION_ONEARGUMENT,
+
+ /**
+ * Sample trace message
+ */
+ MESSAGE_TRACE_SAMPLE,
+
+ /**
+ * Sample error message
+ */
+ MESSAGE_ERROR_SAMPLE;
+
+
+ /**
+ * Static initializer to ensure the resource bundles for this class are loaded...
+ * Here this application loads messages from three bundles
+ */
+ static {
+ EELFResourceManager.loadMessageBundle("org/openecomp/policy/common/logging/eelf/Resources");
+ String id = EELFResourceManager.getIdentifier(RULE_AUDIT_EXEC_INFO);
+ String value = EELFResourceManager.getMessage(RULE_AUDIT_EXEC_INFO);
+
+ System.out.println("*********************** " + id);
+ System.out.println("*********************** " + value);
+
+ }
+}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
new file mode 100644
index 00000000..624ba580
--- /dev/null
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
@@ -0,0 +1,1438 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ECOMP-Logging
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.policy.common.logging.eelf;
+
+import org.slf4j.MDC;
+
+import static org.openecomp.policy.common.logging.eelf.Configuration.*;
+
+import org.openecomp.policy.common.logging.flexlogger.LoggerType;
+import org.openecomp.policy.common.logging.eelf.PolicyLogger;
+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;
+import java.net.UnknownHostException;
+import java.text.SimpleDateFormat;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ *
+ * PolicyLogger contains all the static methods for EELF logging
+ *
+ */
+public class PolicyLogger {
+
+ private static EELFLogger applicationLogger = EELFManager.getInstance()
+ .getApplicationLogger();
+
+ private static EELFLogger errorLogger = EELFManager.getInstance()
+ .getErrorLogger();
+
+ private static EELFLogger metricsLogger = EELFManager.getInstance()
+ .getMetricsLogger();
+
+ private static EELFLogger auditLogger = EELFManager.getInstance()
+ .getAuditLogger();
+
+ private static EELFLogger debugLogger = EELFManager.getInstance()
+ .getDebugLogger();
+
+ private static EventTrackInfo eventTracker = new EventTrackInfo();
+
+ private static String hostName = null;
+ private static String hostAddress = null;
+ private static String component = null;
+
+ private static TimerTask ttrcker = null;
+ private static boolean isEventTrackerRunning = false;
+ private static Timer timer = null;
+
+ //Default:Timer initial delay and the delay between in milliseconds before task is to be execute
+ private static int TIMER_DELAY_TIME = 1000;
+
+ //Default:Timer scheduleAtFixedRate period - time in milliseconds between successive task executions
+ private static int CHECK_INTERVAL = 30 * 1000;
+
+ //Default:longest time an event info can be stored in the concurrentHashMap for logging - in seconds
+ static int EXPIRED_TIME = 60*60*1000*24; //one day
+
+ //Default:the size of the concurrentHashMap which stores the event starting time - when its size reaches this limit, the Timer get executed
+ private static int CONCURRENTHASHMAP_LIMIT = 5000;
+
+ //Default:the size of the concurrentHashMap which stores the event starting time - when its size drops to this point, stop the Timer
+ private static int STOP_CHECK_POINT = 2500;
+
+ private static boolean isOverrideLogbackLevel = false;
+
+ public static Level DEBUG_LEVEL = Level.INFO;
+ public static Level AUDIT_LEVEL = Level.INFO;
+ public static Level METRICS_LEVEL = Level.INFO;
+ public static Level ERROR_LEVEL = Level.ERROR;
+ public static String CLASS_NAME = "ClassName";
+
+
+ static{
+ if (hostName == null || hostAddress == null) {
+ try {
+ hostName = InetAddress.getLocalHost().getHostName();
+ hostAddress = InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyLogger", "UnknownHostException");
+ }
+ }
+ }
+
+ /**
+ * Populates MDC info
+ * @param transId
+ * @return String
+ */
+ public static String postMDCInfoForEvent(String transId) {
+ MDC.clear();
+
+ if(transId == null || transId.isEmpty()){
+ transId = UUID.randomUUID().toString();
+ }
+
+ if(component != null && component.equalsIgnoreCase("DROOLS")){
+ return postMDCInfoForEvent(transId, new DroolsPDPMDCInfo());
+ }
+
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, transId);
+ 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, "PolicyLogger");
+ }
+ Instant startTime = Instant.now();
+ Instant endTime = Instant.now();
+ long ns = Duration.between(startTime, endTime).getSeconds();
+ String unit = " Seconds";
+ if(ns == 1){
+ unit = " Second";
+ }
+
+ if(ns < 1){
+ ns = Duration.between(startTime, endTime).toMillis();
+ unit = " milliseconds";
+ }
+ MDC.put(MDC_INSTANCE_UUID, "");
+ MDC.put(MDC_ALERT_SEVERITY, "");
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
+
+ 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, ns + unit);
+
+ MDC.put(PARTNER_NAME, "N/A");
+
+ MDC.put(STATUS_CODE, "N/A");
+ MDC.put(RESPONSE_CODE, "N/A");
+ MDC.put(RESPONSE_DESCRIPTION, "N/A");
+
+
+ return transId;
+
+ }
+
+ /**
+ * Populate MDC Info using the passed in mdcInfo
+ * @param transId
+ * @param mdcInfo
+ * @return String
+ */
+ private static String postMDCInfoForEvent(String transId, MDCInfo mdcInfo ) {
+
+ MDC.put(MDC_KEY_REQUEST_ID, transId);
+ if(mdcInfo != null && mdcInfo.getMDCInfo() != null && !mdcInfo.getMDCInfo().isEmpty()){
+
+ ConcurrentHashMap<String, String> mdcMap = mdcInfo.getMDCInfo();
+ Iterator<String> keyIterator = mdcMap.keySet().iterator();
+ String key = "";
+
+ while(keyIterator.hasNext()){
+ key = keyIterator.next();
+ MDC.put(key, mdcMap.get(key));
+ }
+ }
+
+ try {
+ MDC.put(MDC_SERVER_FQDN, hostName);
+ MDC.put(MDC_SERVER_IP_ADDRESS, hostAddress);
+ } catch (Exception e) {
+ errorLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyLogger");
+ }
+ Instant startTime = Instant.now();
+ Instant endTime = Instant.now();
+ long ns = Duration.between(startTime, endTime).getSeconds();
+ String unit = " Seconds";
+ if(ns == 1){
+ unit = " Second";
+ }
+
+ if(ns < 1){
+ ns = Duration.between(startTime, endTime).toMillis();
+ unit = " milliseconds";
+ }
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
+
+ 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, ns + unit);
+
+ return transId;
+ }
+
+ /**
+ * Set Timestamps for start, end and duration of logging a transaction
+ */
+ private static void seTimeStamps(){
+
+ Instant startTime = Instant.now();
+ Instant endTime = Instant.now();
+ long ns = Duration.between(startTime, endTime).getSeconds();
+ String unit = " Seconds";
+ if(ns == 1){
+ unit = " Second";
+ }
+
+ if(ns < 1){
+ ns = Duration.between(startTime, endTime).toMillis();
+ unit = " milliseconds";
+ }
+ MDC.put(MDC_INSTANCE_UUID, "");
+ MDC.put(MDC_ALERT_SEVERITY, "");
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
+
+ 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, ns + unit);
+
+ MDC.put(PARTNER_NAME, "N/A");
+
+ MDC.put(STATUS_CODE, "N/A");
+ MDC.put(RESPONSE_CODE, "N/A");
+ MDC.put(RESPONSE_DESCRIPTION, "N/A");
+
+ }
+
+ /**
+ * Sets transaction Id to MDC
+ * @param transId
+ */
+ public static void setTransId(String transId){
+
+ MDC.put(MDC_KEY_REQUEST_ID, transId);
+ }
+
+ /**
+ * Returns current transaction Id used in MDC
+ * @return transId
+ */
+ public static String getTransId(){
+
+ return MDC.get(MDC_KEY_REQUEST_ID);
+ }
+
+ /**
+ * Sets transaction Id to MDC
+ * @param o
+ */
+ public static void postMDCInfoForEvent(Object o){
+ postMDCInfoForEvent(""+o);
+ }
+
+ /**
+ * Resets transaction Id in MDC for the rule triggered by this event
+ * @param transId
+ * @return String
+ */
+ public static String postMDCInfoForTriggeredRule(String transId) {
+
+ MDC.clear();
+
+ if(transId == null || transId.isEmpty()){
+ transId = UUID.randomUUID().toString();
+ }
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, transId);
+ 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, "PolicyLogger");
+ }
+ MDC.put(MDC_INSTANCE_UUID, "");
+ MDC.put(MDC_ALERT_SEVERITY, "");
+ MDC.put(STATUS_CODE, "N/A");
+
+ return transId;
+
+ }
+
+ /**
+ * Resets transaction Id in MDC for the rule triggered by this event
+ * @param o
+ */
+ public static void postMDCUUIDForTriggeredRule(Object o) {
+
+ postMDCInfoForTriggeredRule("" + o);
+
+ }
+
+ // ************************************************************************************************
+ /**
+ * Records the Info event with String [] arguments
+ * @param msg
+ * @param arguments
+ */
+ public static void info(MessageCodes msg, String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ debugLogger.info(msg, arguments);
+ }
+
+ /**
+ * Records the Info event with String [] arguments
+ * @param msg
+ * @param className
+ * @param arguments
+ */
+ public static void info(MessageCodes msg, String className, String... arguments) {
+ MDC.put(CLASS_NAME, className);
+ debugLogger.info(msg, arguments);
+ }
+
+ /**
+ * Records only one String message with its class name
+ * @param className
+ * @param arg0
+ */
+ public static void info( String className, String arg0) {
+ MDC.put(CLASS_NAME, className);
+ debugLogger.info(MessageCodes.GENERAL_INFO, arg0);
+ }
+
+ /**
+ * Records only one String message without its class name passed in
+ * @param arg0
+ */
+ public static void info(String arg0) {
+ MDC.put(CLASS_NAME, "");
+ debugLogger.info(MessageCodes.GENERAL_INFO, arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void info(Object arg0) {
+ MDC.put(CLASS_NAME, "");
+ info(arg0);
+ }
+
+ /**
+ * Records a message with passed in message code, Throwable object, a list of string values
+ * @param msg
+ * @param arg0
+ * @param arguments
+ */
+ public static void info(MessageCodes msg, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ debugLogger.info(msg, arguments2);
+ }
+
+ /**
+ * Records a message with passed in message code, class name, Throwable object, a list of string values
+ * @param msg
+ * @param className
+ * @param arg0
+ * @param arguments
+ */
+ public static void info(MessageCodes msg, String className, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, className);
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ debugLogger.info(msg, arguments2);
+ }
+
+ /**
+ * Records only one String message with its class name
+ * @param arg0 log message
+ * @param className class name
+ */
+ public static void warn( String className, String arg0) {
+ MDC.put(CLASS_NAME, className);
+ debugLogger.warn(MessageCodes.GENERAL_INFO, arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void warn(Object arg0) {
+ MDC.put(CLASS_NAME, "");
+ debugLogger.warn(MessageCodes.GENERAL_WARNING, "" + arg0);
+ }
+
+ /**
+ * Records only one String message without its class name passed in
+ * @param arg0
+ */
+ public static void warn(String arg0) {
+ MDC.put(CLASS_NAME, "");
+ debugLogger.warn(MessageCodes.GENERAL_WARNING, arg0);
+ }
+
+ /**
+ * Records a message with passed in message code and a list of string values
+ * @param msg
+ * @param arguments
+ */
+ public static void warn(MessageCodes msg, String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ debugLogger.warn(msg, arguments);
+ }
+
+ /**
+ * Records a message with passed in message code, class name and a list of string values
+ * @param msg
+ * @param className
+ * @param arguments
+ */
+ public static void warn(MessageCodes msg, String className, String... arguments) {
+ MDC.put(CLASS_NAME, className);
+ debugLogger.warn(msg, arguments);
+ }
+
+ /**
+ * Records a message with passed in message code, Throwable object, a list of string values
+ * @param msg
+ * @param arg0
+ * @param arguments
+ */
+ public static void warn(MessageCodes msg, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ debugLogger.warn(msg, arguments2);
+ }
+
+ /**
+ * Records a message with passed in message code, Throwable object, a list of string values
+ * @param msg
+ * @param className
+ * @param arg0
+ * @param arguments
+ */
+ public static void warn(MessageCodes msg, String className, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, className);
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ debugLogger.warn(msg, arguments2);
+ }
+
+ /**
+ * Records only one String message with its class name
+ * @param className class name
+ * @param arg0 log message
+ */
+ public static void error( String className, String arg0) {
+ MDC.put(CLASS_NAME, className);
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void error(String arg0) {
+ MDC.put(CLASS_NAME, "");
+ MDC.put(ERROR_CATEGORY, "ERROR");
+
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void error(Object arg0) {
+ MDC.put(CLASS_NAME, "");
+ MDC.put(ERROR_CATEGORY, "ERROR");
+
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error(MessageCodes.GENERAL_ERROR, "" + arg0);
+ }
+
+ /**
+ * Records a message with passed in message code, Throwable object, a list of string values
+ * @param msg
+ * @param arg0
+ * @param arguments
+ */
+ public static void error(MessageCodes msg, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ MDC.put(ERROR_CATEGORY, "ERROR");
+
+ if(ErrorCodeMap.hm.get(msg) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(msg).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(msg).getErrorDesc());
+
+ }
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ errorLogger.error(msg, arguments2);
+ }
+
+ /**
+ * Records a message with passed in message code, class name, Throwable object, a list of string values
+ * @param msg
+ * @param className
+ * @param arg0
+ * @param arguments
+ */
+ public static void error(MessageCodes msg, String className, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, className);
+ MDC.put(ERROR_CATEGORY, "ERROR");
+
+ if(ErrorCodeMap.hm.get(msg) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(msg).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(msg).getErrorDesc());
+
+ }
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ errorLogger.error(msg, arguments2);
+ }
+
+ /**
+ * Records a message with passed in message code and a list of string values
+ * @param msg
+ * @param arguments
+ */
+ public static void error(MessageCodes msg, String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ MDC.put(ERROR_CATEGORY, "ERROR");
+
+ if(ErrorCodeMap.hm.get(msg) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(msg).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(msg).getErrorDesc());
+
+ }
+ errorLogger.error(msg, arguments);
+ }
+
+ /**
+ * Records a message with passed in message code and a list of string values
+ * @param msg
+ * @param arguments
+ */
+ public static void debug(MessageCodes msg, String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ debugLogger.debug(msg, arguments);
+ }
+
+ /**
+ * Records only one String message with its class name
+ * @param className
+ * @param arg0
+ */
+ public static void debug( String className, String arg0) {
+ MDC.put(CLASS_NAME, className);
+ debugLogger.debug(MessageCodes.GENERAL_INFO, arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void debug(String arg0) {
+ MDC.put(CLASS_NAME, "");
+ debugLogger.debug(arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void debug(Object arg0) {
+
+ MDC.put(CLASS_NAME, "");
+ debugLogger.debug("" + arg0);
+ }
+
+ /**
+ * Records only one String message with its class name
+ * @param className
+ * @param arg0
+ */
+ public static void audit(String className, Object arg0) {
+ MDC.put(STATUS_CODE, "N/A");
+ MDC.put(CLASS_NAME, className);
+ auditLogger.info("" + arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void audit(Object arg0) {
+ MDC.put(STATUS_CODE, "N/A");
+ MDC.put(CLASS_NAME, "");
+ auditLogger.info("" + arg0);
+ }
+
+ /**
+ * Records a message with passed in message code, hrowable object, a list of string values
+ * @param msg
+ * @param arg0
+ * @param arguments
+ */
+ public static void debug(MessageCodes msg, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, "");
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ errorLogger.error(msg, arguments2);
+ }
+
+ /**
+ * Records a message with passed in message code, class name, Throwable object, a list of string values
+ * @param msg
+ * @param className
+ * @param arg0
+ * @param arguments
+ */
+ public static void debug(MessageCodes msg, String className, Throwable arg0,
+ String... arguments) {
+ MDC.put(CLASS_NAME, className);
+ String arguments2 = getNormalizedStackTrace(arg0, arguments);
+ errorLogger.error(msg, arguments2);
+ }
+ /**
+ * returns true for enabled, false for not enabled
+ */
+ public static boolean isDebugEnabled(){
+
+ return debugLogger.isDebugEnabled();
+ }
+
+ /**
+ * returns true for enabled, false for not enabled
+ */
+ public static boolean isErrorEnabled(){
+
+ return errorLogger.isErrorEnabled();
+ }
+
+ /**
+ * returns true for enabled, false for not enabled
+ */
+ public static boolean isWarnEnabled(){
+
+ return debugLogger.isWarnEnabled();
+ }
+
+ /**
+ * returns true for enabled, false for not enabled
+ */
+ public static boolean isInfoEnabled1(){
+
+ return debugLogger.isInfoEnabled();
+ }
+
+ /**
+ * returns true for enabled, false for not enabled
+ */
+ public static boolean isAuditEnabled(){
+
+ return debugLogger.isInfoEnabled();
+ }
+
+ /**
+ * returns true for enabled, false for not enabled
+ */
+ public static boolean isInfoEnabled(){
+
+ return debugLogger.isInfoEnabled();
+ }
+
+ /**
+ * Records only one String message with its class name
+ * @param className
+ * @param arg0
+ */
+ public static void trace( String className, String arg0) {
+ MDC.put(CLASS_NAME, className);
+ errorLogger.info(MessageCodes.GENERAL_INFO, arg0);
+ }
+
+ /**
+ * Records only one String message
+ * @param arg0
+ */
+ public static void trace(Object arg0){
+
+ MDC.put(CLASS_NAME, "");
+ debugLogger.trace(""+arg0);
+ }
+ /**
+ * Records the starting time of the event with its request Id as the key
+ * @param eventId
+ */
+ public static void recordAuditEventStart(String eventId) {
+
+ MDC.put(STATUS_CODE, "N/A");
+ postMDCInfoForEvent(eventId);
+
+ if(eventTracker == null){
+ eventTracker = new EventTrackInfo();
+ }
+ EventData event = new EventData();
+ event.setRequestID(eventId);
+ event.setStartTime(Instant.now());
+ eventTracker.storeEventData(event);
+ MDC.put(MDC_KEY_REQUEST_ID, eventId);
+ debugLogger.info("CONCURRENTHASHMAP_LIMIT : " + CONCURRENTHASHMAP_LIMIT);
+ //--- Tracking the size of the concurrentHashMap, if it is above limit, keep EventTrack Timer running
+ int size = eventTracker.getEventInfo().size();
+
+ debugLogger.info("EventInfo concurrentHashMap Size : " + size + " on " + new Date());
+ debugLogger.info("isEventTrackerRunning : " + isEventTrackerRunning);
+
+ if( size >= CONCURRENTHASHMAP_LIMIT){
+
+
+ if(!isEventTrackerRunning){
+
+ startCleanUp();
+ isEventTrackerRunning = true;
+ }
+
+ }else if( size <= STOP_CHECK_POINT){
+
+ if(isEventTrackerRunning){
+ stopCleanUp();
+ }
+ }
+ }
+
+ /**
+ * Records the starting time of the event with its request Id as the key
+ * @param eventId
+ */
+ public static void recordAuditEventStart(UUID eventId) {
+
+ if(eventId == null){
+ return;
+ }
+
+ if(eventTracker == null){
+ eventTracker = new EventTrackInfo();
+ }
+
+ recordAuditEventStart(eventId.toString());
+
+ }
+
+ /**
+ * Records the ending time of the event with its request Id as the key
+ * @param eventId
+ * @param rule
+ */
+ public static void recordAuditEventEnd(String eventId, String rule) {
+
+ if(eventTracker == null){
+ return;
+ }
+ if(eventId == null){
+ return;
+ }
+
+ creatAuditEventTrackingRecord(eventId, rule, "");
+
+ }
+
+ /**
+ * Records the ending time of the event with its request Id as the key
+ * @param eventId
+ * @param rule
+ * @param policyVersion
+ */
+ public static void recordAuditEventEnd(String eventId, String rule , String policyVersion) {
+
+ if(eventTracker == null){
+ return;
+ }
+ if(eventId == null){
+ return;
+ }
+
+ creatAuditEventTrackingRecord(eventId, rule, policyVersion);
+
+ }
+
+ /**
+ * Records the ending time of the event with its request Id as the key
+ * @param eventId
+ * @param rule
+ * @param policyVersion
+ */
+ public static void recordAuditEventEnd(UUID eventId, String rule, String policyVersion) {
+
+ if(eventId == null){
+ return;
+ }
+
+ recordAuditEventEnd(eventId.toString(), rule, policyVersion);
+
+ }
+
+
+ /**
+ * Records the ending time of the event with its request Id as the key
+ * @param eventId
+ * @param rule
+ */
+ public static void recordAuditEventEnd(UUID eventId, String rule) {
+
+ if(eventId == null){
+ return;
+ }
+
+ recordAuditEventEnd(eventId.toString(), rule);
+
+ }
+
+ /**
+ * Records the ending time of the event with its request Id as the key
+ * @param eventId
+ * @param rule
+ * @param policyVersion
+ */
+ public static void creatAuditEventTrackingRecord(String eventId, String rule, String policyVersion) {
+
+ if(eventTracker == null){
+ return;
+ }
+
+ EventData event = eventTracker.getEventDataByRequestID(eventId);
+
+ if(event != null){
+ Instant endTime = event.getEndTime();
+ if(endTime == null){
+ endTime = Instant.now();
+ }
+ MDC.put(STATUS_CODE, "COMPLETE");
+ recordAuditEventStartToEnd(eventId, rule, event.getStartTime(), endTime, policyVersion);
+ }
+ }
+
+ /**
+ * Records the ending time of the event with its request Id as the key
+ * @param eventId
+ * @param rule
+ */
+ public static void creatAuditEventTrackingRecord(UUID eventId, String rule) {
+
+ if(eventId == null){
+ return;
+ }
+
+ if(eventTracker == null){
+ return;
+ }
+
+ EventData event = eventTracker.getEventDataByRequestID(eventId.toString());
+
+ if(event != null){
+ Instant endTime = event.getEndTime();
+ if(endTime == null){
+ endTime = Instant.now();
+ }
+
+ recordAuditEventStartToEnd(eventId.toString(), rule, event.getStartTime(), endTime, "N/A");
+ }
+ }
+
+ public static EventTrackInfo getEventTracker() {
+ return eventTracker;
+ }
+
+ /**
+ * Records the audit with an event starting and ending times
+ * @param eventId
+ * @param rule
+ * @param startTime
+ * @param endTime
+ * @param policyVersion
+ */
+ public static void recordAuditEventStartToEnd(String eventId, String rule, Instant startTime, Instant endTime, String policyVersion) {
+
+ if(startTime == null || endTime == null){
+ return;
+ }
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ if(eventId != null && !eventId.isEmpty()){
+ MDC.put(MDC_KEY_REQUEST_ID, eventId);
+ }
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
+
+ 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(RESPONSE_CODE, "N/A");
+ MDC.put(RESPONSE_DESCRIPTION, "N/A");
+
+ long ns = Duration.between(startTime, endTime).getSeconds();
+ String unit = " Seconds";
+ if(ns == 1){
+ unit = " Second";
+ }
+
+ if(ns < 1){
+ ns = Duration.between(startTime, endTime).toMillis();
+ unit = " milliseconds";
+ }
+
+ MDC.put(ELAPSED_TIME, ns + unit);
+
+ auditLogger.info(MessageCodes.RULE_AUDIT_START_END_INFO,
+ serviceName, rule, startTime.toString(), endTime.toString(), ns+unit, policyVersion);
+
+ //--- remove the record from the concurrentHashMap
+ if(eventTracker != null){
+ if(eventTracker.getEventDataByRequestID(eventId) != null){
+ eventTracker.remove(eventId);
+ debugLogger.info("eventTracker.remove(" + eventId + ")");
+ }
+ }
+ }
+
+ /**
+ * Records the metrics with an event Id and log message
+ * @param eventId
+ * @param arg1
+ */
+ public static void recordMetricEvent(String eventId, String arg1) {
+
+ seTimeStamps();
+
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ MDC.put(MDC_KEY_REQUEST_ID, eventId);
+ metricsLogger.info(MessageCodes.RULE_AUDIT_END_INFO,
+ serviceName, arg1);
+
+ }
+
+ /**
+ * Records the metrics with an event Id, class name and log message
+ * @param eventId
+ * @param className
+ * @param arg1
+ */
+ public static void recordMetricEvent(String eventId, String className,String arg1) {
+
+ seTimeStamps();
+
+ MDC.put(CLASS_NAME, className);
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ MDC.put(MDC_KEY_REQUEST_ID, eventId);
+ metricsLogger.info(MessageCodes.RULE_AUDIT_END_INFO,
+ serviceName, arg1);
+ }
+
+ /**
+ * Records the metrics with an event Id and log message
+ * @param eventId
+ * @param arg1
+ */
+ public static void recordMetricEvent(UUID eventId, String arg1) {
+
+ if(eventId == null){
+ return;
+ }
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ MDC.put(MDC_KEY_REQUEST_ID, eventId.toString());
+ metricsLogger.info(MessageCodes.RULE_AUDIT_END_INFO,
+ serviceName, arg1);
+ }
+
+ /**
+ * Records a String message for metrics logs
+ * @param arg0
+ */
+ public static void recordMetricEvent(String arg0) {
+ seTimeStamps();
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO,
+ serviceName, arg0);
+ }
+
+
+ /**
+ * Records the metrics event with a String message
+ * @param arg0
+ */
+ public static void metrics(String arg0) {
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO,
+ serviceName, arg0);
+ }
+
+ /**
+ * Records the metrics event with a class name and a String message
+ * @param arg0
+ */
+ public static void metrics(String className, Object arg0) {
+ seTimeStamps();
+ MDC.put(CLASS_NAME, className);
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO,
+ serviceName, ""+arg0);
+ }
+
+ /**
+ * Records the metrics event with a String message
+ * @param arg0
+ */
+ public static void metrics(Object arg0) {
+ seTimeStamps();
+ MDC.put(CLASS_NAME, "");
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO,
+ serviceName, ""+arg0);
+ }
+
+ /**
+ * Records the metrics event with a String message
+ * @param arg0
+ */
+ public static void metricsPrintln(String arg0) {
+ MDC.clear();
+ metricsLogger.info(arg0);
+ }
+
+ /**
+ * Removes all the return lines from the printStackTrace
+ * @param t
+ * @param arguments
+ */
+ private static String getNormalizedStackTrace (Throwable t, String...arguments) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ String newStValue = sw.toString().replace ('|', '!').replace ("\n", " - ");
+ int curSize = (arguments == null ? 0 : arguments.length);
+ StringBuffer newArgument = new StringBuffer();
+ for(int i=0; i<curSize; i++) {
+ newArgument.append(arguments[i]);
+ newArgument.append(":");
+ }
+ newArgument.append(newStValue);
+ return newArgument.toString();
+ }
+
+ /**
+ * Starts the process of cleaning up the ConcurrentHashMap of EventData
+ */
+ private static void startCleanUp(){
+
+ if(!isEventTrackerRunning) {
+ ttrcker = new EventTrackInfoHandler();
+ timer = new Timer(true);
+ timer.scheduleAtFixedRate(ttrcker, TIMER_DELAY_TIME, CHECK_INTERVAL);
+ debugLogger.info("EventTrackInfoHandler begins! : " + new Date());
+ }else{
+ debugLogger.info("Timer is still running : " + new Date());
+
+ }
+ }
+
+
+ /**
+ * Stops the process of cleaning up the ConcurrentHashMap of EventData
+ */
+ private static void stopCleanUp(){
+
+ if(isEventTrackerRunning && timer != null){
+ timer.cancel();
+ timer.purge();
+ debugLogger.info("Timer stopped: " + new Date());
+ }else{
+ debugLogger.info("Timer was already stopped : " + new Date());
+
+ }
+ isEventTrackerRunning = false;
+
+ }
+
+ /**
+ * Loads all the attributes from policyLogger.properties file
+ */
+ public static LoggerType init(Properties properties) throws Exception {
+ // read in properties
+ Properties logger_properties = properties;
+ LoggerType logger_type = LoggerType.EELF;
+
+ // fetch and verify definitions of some properties
+ try{
+
+ int timerDelayTime = Integer.parseInt(logger_properties.getProperty("timer.delay.time"));
+ int checkInterval = Integer.parseInt(logger_properties.getProperty("check.interval"));
+ int expiredDate = Integer.parseInt(logger_properties.getProperty("event.expired.time"));
+ int concurrentHashMapLimit = Integer.parseInt(logger_properties.getProperty("concurrentHashMap.limit"));
+ int stopCheckPoint = Integer.parseInt(logger_properties.getProperty("stop.check.point"));
+ String loggerType = logger_properties.getProperty("logger.type");
+
+ String debugLevel = logger_properties.getProperty("debugLogger.level");
+ String metricsLevel = logger_properties.getProperty("metricsLogger.level");
+ String auditLevel = logger_properties.getProperty("error.level");
+ String errorLevel = logger_properties.getProperty("audit.level");
+ component = logger_properties.getProperty("policy.component");
+ String overrideLogbackLevel = logger_properties.getProperty("override.logback.level.setup");
+
+ if(overrideLogbackLevel != null && !overrideLogbackLevel.isEmpty()) {
+ if(overrideLogbackLevel.equalsIgnoreCase("TRUE")){
+ isOverrideLogbackLevel = true;
+ }else{
+ isOverrideLogbackLevel = false;
+ }
+ }
+
+
+ if (debugLevel != null && !debugLevel.isEmpty()){
+
+ DEBUG_LEVEL = Level.valueOf(debugLevel);
+
+ }
+ //Only check if it is to turn off or not
+ if (errorLevel != null && errorLevel.equalsIgnoreCase(Level.OFF.toString())){
+
+ ERROR_LEVEL = Level.valueOf(errorLevel);
+
+ }
+ //Only check if it is to turn off or not
+ if (metricsLevel != null && metricsLevel.equalsIgnoreCase(Level.OFF.toString())){
+
+ METRICS_LEVEL = Level.valueOf(metricsLevel);
+
+ }
+ //Only check if it is to turn off or not
+ if (auditLevel != null && auditLevel.equalsIgnoreCase(Level.OFF.toString())){
+
+ AUDIT_LEVEL = Level.valueOf(auditLevel);
+
+ }
+
+ if(isOverrideLogbackLevel){
+
+ debugLogger.setLevel(DEBUG_LEVEL);
+ metricsLogger.setLevel(METRICS_LEVEL);
+ auditLogger.setLevel(AUDIT_LEVEL);
+ errorLogger.setLevel(ERROR_LEVEL);
+
+ }
+ isEventTrackerRunning = false;
+
+ debugLogger.info("timerDelayTiime value: " + timerDelayTime);
+
+ debugLogger.info("checkInterval value: " + checkInterval);
+
+ debugLogger.info("expiredDate value: " + expiredDate);
+
+ debugLogger.info("concurrentHashMapLimit value: " + concurrentHashMapLimit);
+
+ debugLogger.info("loggerType value: " + loggerType);
+
+ debugLogger.info("debugLogger level: " + debugLevel);
+
+ debugLogger.info("component: " + component);
+
+ if (timerDelayTime > 0){
+
+ TIMER_DELAY_TIME = timerDelayTime;
+
+ }else {
+ MDC.put(ERROR_CATEGORY, "ERROR");
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error("failed to get the timer.delay.time, so use its default value: " + TIMER_DELAY_TIME);
+ }
+
+ if (checkInterval > 0){
+
+ CHECK_INTERVAL = checkInterval;
+
+ }else {
+ MDC.put(ERROR_CATEGORY, "ERROR");
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error("failed to get the check.interval, so use its default value: " + CHECK_INTERVAL);
+ }
+
+ if (expiredDate > 0){
+
+ EXPIRED_TIME = expiredDate;
+
+ }else {
+ MDC.put(ERROR_CATEGORY, "ERROR");
+
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error("failed to get the event.expired.time, so use its default value: " + EXPIRED_TIME);
+ }
+
+ if (concurrentHashMapLimit > 0){
+
+ CONCURRENTHASHMAP_LIMIT = concurrentHashMapLimit;
+
+ }else {
+ MDC.put(ERROR_CATEGORY, "ERROR");
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error("failed to get the concurrentHashMap.limit, so use its default value: " + CONCURRENTHASHMAP_LIMIT);
+ }
+
+ if (stopCheckPoint > 0){
+
+ STOP_CHECK_POINT = stopCheckPoint;
+
+ }else {
+ MDC.put(ERROR_CATEGORY, "ERROR");
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error("failed to get the stop.check.point, so use its default value: " + STOP_CHECK_POINT);
+ }
+
+ if (loggerType != null){
+
+ if (loggerType.equalsIgnoreCase("EELF")){
+
+ logger_type = LoggerType.EELF;
+
+ }else if (loggerType.equalsIgnoreCase("LOG4J")){
+
+ logger_type = LoggerType.LOG4J;
+
+ }else if (loggerType.equalsIgnoreCase("SYSTEMOUT")){
+
+ logger_type = LoggerType.SYSTEMOUT;
+
+ }
+
+ }
+
+ if (debugLevel != null && !debugLevel.isEmpty()){
+
+ DEBUG_LEVEL = Level.valueOf(debugLevel);
+
+ }
+ //Only check if it is to turn off or not
+ if (errorLevel != null && errorLevel.equalsIgnoreCase(Level.OFF.toString())){
+
+ ERROR_LEVEL = Level.valueOf(errorLevel);
+
+ }
+ //Only check if it is to turn off or not
+ if (metricsLevel != null && metricsLevel.equalsIgnoreCase(Level.OFF.toString())){
+
+ METRICS_LEVEL = Level.valueOf(metricsLevel);
+
+ }
+ //Only check if it is to turn off or not
+ if (auditLevel != null && auditLevel.equalsIgnoreCase(Level.OFF.toString())){
+
+ AUDIT_LEVEL = Level.valueOf(auditLevel);
+
+ }
+
+ }catch(Exception e){
+ MDC.put(ERROR_CATEGORY, "ERROR");
+
+ if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+
+ }
+ errorLogger.error("failed to get the policyLogger.properties, so use their default values",e);
+ }
+
+ return logger_type;
+
+ }
+
+ /**
+ * Sets Debug Level
+ */
+ public static void setDebugLevel(String debugLevel){
+
+ if(isOverrideLogbackLevel){
+ PolicyLogger.DEBUG_LEVEL = Level.valueOf(debugLevel);
+ debugLogger.setLevel(DEBUG_LEVEL);
+ }
+
+ }
+
+ /**
+ * Sets Error OFF or ON
+ */
+ public static void setErrorLevel(String errorLevel){
+
+ if(isOverrideLogbackLevel){
+ if(errorLevel != null && errorLevel.equalsIgnoreCase("OFF")){
+ PolicyLogger.ERROR_LEVEL = Level.OFF;
+ errorLogger.setLevel(ERROR_LEVEL);
+ }else{
+ //--- set default value
+ errorLogger.setLevel(Level.ERROR);
+ PolicyLogger.ERROR_LEVEL = Level.ERROR;
+ }
+ }
+ }
+
+ /**
+ * Sets Metrics OFF or ON
+ */
+ public static void setMetricsLevel(String metricsLevel){
+
+ if(isOverrideLogbackLevel){
+ if(metricsLevel != null && metricsLevel.equalsIgnoreCase("OFF")){
+ PolicyLogger.METRICS_LEVEL = Level.OFF;
+ metricsLogger.setLevel(METRICS_LEVEL);
+ }else {
+ //--- set default value
+ metricsLogger.setLevel(Level.INFO);
+ PolicyLogger.METRICS_LEVEL = Level.INFO;
+ }
+ }
+
+ }
+
+ /**
+ * Sets Audit OFF or ON
+ */
+ public static void setAuditLevel(String auditLevel){
+
+ if(isOverrideLogbackLevel){
+ if(auditLevel != null && auditLevel.equalsIgnoreCase("OFF")){
+ PolicyLogger.AUDIT_LEVEL = Level.OFF;
+ auditLogger.setLevel(AUDIT_LEVEL);
+ }else {
+ //--- set default value
+ auditLogger.setLevel(Level.INFO);
+ PolicyLogger.AUDIT_LEVEL = Level.INFO;
+ }
+ }
+ }
+
+ /**
+ * Returns true for overriding logback levels; returns false for not
+ */
+ public static boolean isOverrideLogbackLevel(){
+
+ return isOverrideLogbackLevel;
+ }
+
+ /**
+ * Sets true for overriding logback levels; sets false for not
+ */
+ public static void setOverrideLogbackLevel(boolean odl){
+
+ isOverrideLogbackLevel = odl;
+
+ }
+ /**
+ * Sets server information to MDC
+ */
+ public static void setServerInfo(String serverHost, String serverPort){
+ MDC.put(SERVER_NAME, serverHost+":"+serverPort);
+ }
+
+}