aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java')
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java421
1 files changed, 139 insertions, 282 deletions
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);
}
-
}