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.java379
1 files changed, 218 insertions, 161 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 f1b25d71..662ca764 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 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.
@@ -34,6 +34,7 @@ import static org.onap.policy.common.logging.eelf.OnapConfigProperties.END_TIME_
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.INVOCATION_ID;
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;
@@ -57,26 +58,31 @@ 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.ConcurrentMap;
import java.util.function.Consumer;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.logging.OnapLoggingUtils;
import org.onap.policy.common.logging.flexlogger.LoggerType;
import org.slf4j.MDC;
/**
* PolicyLogger contains all the static methods for EELF logging.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PolicyLogger {
- private static EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
+ private static EELFLogger errorLogger = EELFManager.getErrorLogger();
- private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ private static EELFLogger metricsLogger = EELFManager.getMetricsLogger();
- private static EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+ private static EELFLogger auditLogger = EELFManager.getAuditLogger();
- private static EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
+ private static EELFLogger debugLogger = EELFManager.getDebugLogger();
private static final String POLICY_LOGGER = "PolicyLogger";
@@ -86,7 +92,6 @@ public class PolicyLogger {
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;
@@ -110,7 +115,9 @@ public class PolicyLogger {
// size drops to this point, stop the Timer
private static int stopCheckPoint = 2500;
- private static boolean isOverrideLogbackLevel = false;
+ @Getter
+ @Setter
+ private static boolean overrideLogbackLevel = false;
private static Level debugLevel = Level.INFO;
private static Level auditLevel = Level.INFO;
@@ -133,10 +140,6 @@ public class PolicyLogger {
}
}
- private PolicyLogger() {
-
- }
-
public static synchronized Level getDebugLevel() {
return debugLevel;
}
@@ -150,7 +153,7 @@ public class PolicyLogger {
*/
public static synchronized void setDebugLevel(String newDebugLevel) {
- if (isOverrideLogbackLevel) {
+ if (overrideLogbackLevel) {
PolicyLogger.debugLevel = Level.valueOf(newDebugLevel);
debugLogger.setLevel(debugLevel);
}
@@ -170,7 +173,7 @@ public class PolicyLogger {
*/
public static synchronized void setAuditLevel(String newAuditLevel) {
- if (isOverrideLogbackLevel) {
+ if (overrideLogbackLevel) {
if ("OFF".equalsIgnoreCase(newAuditLevel)) {
PolicyLogger.auditLevel = Level.OFF;
auditLogger.setLevel(auditLevel);
@@ -195,7 +198,7 @@ public class PolicyLogger {
*/
public static synchronized void setMetricsLevel(String newMetricsLevel) {
- if (isOverrideLogbackLevel) {
+ if (overrideLogbackLevel) {
if ("OFF".equalsIgnoreCase(newMetricsLevel)) {
PolicyLogger.metricsLevel = Level.OFF;
metricsLogger.setLevel(metricsLevel);
@@ -221,7 +224,7 @@ public class PolicyLogger {
*/
public static synchronized void setErrorLevel(String newErrorLevel) {
- if (isOverrideLogbackLevel) {
+ if (overrideLogbackLevel) {
if ("OFF".equalsIgnoreCase(newErrorLevel)) {
PolicyLogger.errorLevel = Level.OFF;
errorLogger.setLevel(errorLevel);
@@ -301,8 +304,8 @@ public class PolicyLogger {
setMdcHostInfo();
- Instant startTime = Instant.now();
- Instant endTime = Instant.now();
+ var startTime = Instant.now();
+ var endTime = Instant.now();
seTimeStamps(startTime, endTime);
@@ -331,12 +334,11 @@ public class PolicyLogger {
* Set Timestamps for start, end and duration of logging a transaction.
*/
private static void seTimeStamps() {
-
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
- Instant startTime = Instant.now();
- Instant endTime = Instant.now();
+ var startTime = Instant.now();
+ var endTime = Instant.now();
seTimeStamps(startTime, endTime);
@@ -349,7 +351,7 @@ public class PolicyLogger {
}
private static void seTimeStamps(Instant startTime, Instant endTime) {
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
+ var sdf = new SimpleDateFormat(DATE_FORMAT);
String formatedTime = sdf.format(Date.from(startTime));
MDC.put(BEGIN_TIME_STAMP, formatedTime);
@@ -433,18 +435,6 @@ public class PolicyLogger {
}
/**
- * Records only one String message with its class name.
- *
- * @param className the class name
- * @param arg0 the message
- */
- public static void info(String className, String arg0) {
- MDC.put(classNameProp, className);
- debugLogger.info(MessageCodes.GENERAL_INFO, arg0);
- }
-
-
- /**
* Records only one String message.
*
* @param arg0 the message
@@ -483,14 +473,29 @@ public class PolicyLogger {
}
/**
- * Records only one String message with its class name.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param arg0 log message
- * @param className class name
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void warn(String className, String arg0) {
- MDC.put(classNameProp, className);
- debugLogger.warn(MessageCodes.GENERAL_INFO, arg0);
+ public static void info(String message, Object... arguments) {
+ if (!debugLogger.isInfoEnabled()) {
+ return;
+ }
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ debugLogger.info(MessageCodes.GENERAL_INFO,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable) arguments[0], "");
+ debugLogger.info(MessageCodes.GENERAL_INFO, message + arguments2);
+ return;
+ }
+
+ MDC.put(classNameProp, "");
+ debugLogger.info(message, arguments);
}
/**
@@ -553,19 +558,28 @@ public class PolicyLogger {
}
/**
- * Records only one String message with its class name.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param className class name
- * @param arg0 log message
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void error(String className, String arg0) {
- MDC.put(classNameProp, className);
- 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());
-
+ public static void warn(String message, Object... arguments) {
+ if (!debugLogger.isWarnEnabled()) {
+ return;
}
- errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ debugLogger.warn(MessageCodes.GENERAL_INFO,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable) arguments[0], "");
+ debugLogger.warn(MessageCodes.GENERAL_INFO, message + arguments2);
+ return;
+ }
+ MDC.put(classNameProp, "");
+ debugLogger.warn(message, arguments);
}
/**
@@ -575,13 +589,7 @@ public class PolicyLogger {
*/
public static void error(String arg0) {
MDC.put(classNameProp, "");
- 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());
-
- }
+ setErrorCode(MessageCodes.GENERAL_ERROR);
errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
}
@@ -592,13 +600,7 @@ public class PolicyLogger {
*/
public static void error(Object arg0) {
MDC.put(classNameProp, "");
- 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());
-
- }
+ setErrorCode(MessageCodes.GENERAL_ERROR);
errorLogger.error(MessageCodes.GENERAL_ERROR, "" + arg0);
}
@@ -611,13 +613,7 @@ public class PolicyLogger {
*/
public static void error(MessageCodes msg, Throwable arg0, String... arguments) {
MDC.put(classNameProp, "");
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
-
- if (ErrorCodeMap.getErrorCodeInfo(msg) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(msg).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(msg).getErrorDesc());
-
- }
+ setErrorCode(msg);
String arguments2 = getNormalizedStackTrace(arg0, arguments);
errorLogger.error(msg, arguments2);
}
@@ -633,13 +629,7 @@ public class PolicyLogger {
*/
public static void error(MessageCodes msg, String className, Throwable arg0, String... arguments) {
MDC.put(classNameProp, className);
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
-
- if (ErrorCodeMap.getErrorCodeInfo(msg) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(msg).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(msg).getErrorDesc());
-
- }
+ setErrorCode(msg);
String arguments2 = getNormalizedStackTrace(arg0, arguments);
errorLogger.error(msg, arguments2);
}
@@ -652,14 +642,35 @@ public class PolicyLogger {
*/
public static void error(MessageCodes msg, String... arguments) {
MDC.put(classNameProp, "");
- MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
-
- if (ErrorCodeMap.getErrorCodeInfo(msg) != null) {
- MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(msg).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(msg).getErrorDesc());
+ setErrorCode(msg);
+ errorLogger.error(msg, arguments);
+ }
+ /**
+ * Records a message with passed in message text and variable number of arguments.
+ *
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
+ */
+ public static void error(String message, Object... arguments) {
+ if (!errorLogger.isErrorEnabled()) {
+ return;
}
- errorLogger.error(msg, arguments);
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ setErrorCode(MessageCodes.GENERAL_ERROR);
+ errorLogger.error(MessageCodes.GENERAL_ERROR,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable) arguments[0], "");
+ errorLogger.error(MessageCodes.GENERAL_ERROR, message + arguments2);
+ return;
+ }
+ MDC.put(classNameProp, "");
+ setErrorCode(MessageCodes.GENERAL_ERROR);
+ errorLogger.error(message, arguments);
}
/**
@@ -674,17 +685,6 @@ public class PolicyLogger {
}
/**
- * Records only one String message with its class name.
- *
- * @param className the class name
- * @param arg0 the message
- */
- public static void debug(String className, String arg0) {
- MDC.put(classNameProp, className);
- debugLogger.debug(MessageCodes.GENERAL_INFO, arg0);
- }
-
- /**
* Records only one String message.
*
* @param arg0 the message
@@ -702,7 +702,7 @@ public class PolicyLogger {
public static void debug(Object arg0) {
MDC.put(classNameProp, "");
- debugLogger.debug("" + arg0);
+ debugLogger.debug("{}", arg0);
}
/**
@@ -734,15 +734,28 @@ public class PolicyLogger {
}
/**
- * Records only one String message with its class name.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param className the class name
- * @param arg0 the message
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void audit(String className, Object arg0) {
- MDC.put(STATUS_CODE, COMPLETE_STATUS);
- MDC.put(classNameProp, className);
- auditLogger.info("" + arg0);
+ public static void debug(String message, Object... arguments) {
+ if (!debugLogger.isDebugEnabled()) {
+ return;
+ }
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ debugLogger.debug(MessageCodes.GENERAL_INFO,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable) arguments[0], "");
+ debugLogger.debug(MessageCodes.GENERAL_INFO, message + arguments2);
+ return;
+ }
+ MDC.put(classNameProp, "");
+ debugLogger.debug(message, arguments);
}
/**
@@ -751,9 +764,34 @@ public class PolicyLogger {
* @param arg0 the message
*/
public static void audit(Object arg0) {
+ MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
MDC.put(STATUS_CODE, COMPLETE_STATUS);
+ MDC.put(RESPONSE_CODE, "0");
MDC.put(classNameProp, "");
- auditLogger.info("" + arg0);
+ auditLogger.info("{}", arg0);
+ }
+
+ /**
+ * Records a message with passed in message text and variable number of arguments.
+ *
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
+ */
+ public static void audit(String message, Object... arguments) {
+ if (!auditLogger.isInfoEnabled()) {
+ return;
+ }
+ MDC.put(INVOCATION_ID, postMdcInfoForEvent(null));
+ MDC.put(STATUS_CODE, COMPLETE_STATUS);
+ MDC.put(RESPONSE_CODE, "0");
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ auditLogger.info("{}", arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+
+ MDC.put(classNameProp, "");
+ auditLogger.info(message, arguments);
}
/**
@@ -823,7 +861,7 @@ public class PolicyLogger {
public static void trace(Object arg0) {
MDC.put(classNameProp, "");
- debugLogger.trace("" + arg0);
+ debugLogger.trace("{}", arg0);
}
/**
@@ -839,18 +877,18 @@ public class PolicyLogger {
if (eventTracker == null) {
eventTracker = new EventTrackInfo();
}
- EventData event = new EventData();
+ var event = new EventData();
event.setRequestId(eventId);
event.setStartTime(Instant.now());
eventTracker.storeEventData(event);
MDC.put(MDC_KEY_REQUEST_ID, eventId);
- debugLogger.info("CONCURRENTHASHMAP_LIMIT : " + concurrentHashMapLimit);
+ debugLogger.info("CONCURRENTHASHMAP_LIMIT : {}", concurrentHashMapLimit);
// --- 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);
+ debugLogger.info("EventInfo concurrentHashMap Size : {} on {}", size, new Date());
+ debugLogger.info("isEventTrackerRunning : {}", isEventTrackerRunning);
if (size >= concurrentHashMapLimit) {
@@ -972,7 +1010,7 @@ public class PolicyLogger {
return;
}
- EventData event = eventTracker.getEventDataByRequestId(eventId);
+ var event = eventTracker.getEventDataByRequestId(eventId);
if (event != null) {
Instant endTime = event.getEndTime();
@@ -1000,7 +1038,7 @@ public class PolicyLogger {
return;
}
- EventData event = eventTracker.getEventDataByRequestId(eventId.toString());
+ var event = eventTracker.getEventDataByRequestId(eventId.toString());
if (event != null) {
Instant endTime = event.getEndTime();
@@ -1049,7 +1087,7 @@ public class PolicyLogger {
if (eventTracker != null && eventTracker.getEventDataByRequestId(eventId) != null) {
eventTracker.remove(eventId);
- debugLogger.info("eventTracker.remove(" + eventId + ")");
+ debugLogger.info("eventTracker.remove({})", eventId);
}
}
@@ -1066,6 +1104,7 @@ public class PolicyLogger {
String serviceName = MDC.get(MDC_SERVICE_NAME);
MDC.put(MDC_KEY_REQUEST_ID, eventId);
+ MDC.put(STATUS_CODE, COMPLETE_STATUS);
metricsLogger.info(MessageCodes.RULE_AUDIT_END_INFO, serviceName, arg1);
}
@@ -1084,6 +1123,7 @@ public class PolicyLogger {
MDC.put(classNameProp, className);
String serviceName = MDC.get(MDC_SERVICE_NAME);
MDC.put(MDC_KEY_REQUEST_ID, eventId);
+ MDC.put(STATUS_CODE, COMPLETE_STATUS);
metricsLogger.info(MessageCodes.RULE_AUDIT_END_INFO, serviceName, arg1);
}
@@ -1121,32 +1161,55 @@ public class PolicyLogger {
* @param arg0 the message
*/
public static void metrics(String arg0) {
+ seTimeStamps();
+ MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
+ MDC.put(RESPONSE_CODE, "0");
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.
+ * Records the metrics event with a String message.
*
* @param arg0 the message
*/
- public static void metrics(String className, Object arg0) {
+ public static void metrics(Object arg0) {
seTimeStamps();
- MDC.put(classNameProp, className);
+ MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
+ MDC.put(RESPONSE_CODE, "0");
+ MDC.put(classNameProp, "");
String serviceName = MDC.get(MDC_SERVICE_NAME);
metricsLogger.info(MessageCodes.RULE_METRICS_INFO, serviceName, "" + arg0);
}
/**
- * Records the metrics event with a String message.
+ * Records a message with passed in message text and variable number of arguments.
*
- * @param arg0 the message
+ * @param message class name if one argument, otherwise message text
+ * @param arguments variable number of arguments
*/
- public static void metrics(Object arg0) {
+ public static void metrics(String message, Object... arguments) {
+ if (!metricsLogger.isInfoEnabled()) {
+ return;
+ }
seTimeStamps();
+ MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
+ MDC.put(RESPONSE_CODE, "0");
+ if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) {
+ MDC.put(classNameProp, message);
+ String serviceName = MDC.get(MDC_SERVICE_NAME);
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO, serviceName,
+ arguments[0] == null ? "" : arguments[0].toString());
+ return;
+ }
+ if (arguments.length == 1 && OnapLoggingUtils.isThrowable(arguments[0])) {
+ String arguments2 = getNormalizedStackTrace((Throwable) arguments[0], "");
+ metricsLogger.info(MessageCodes.RULE_METRICS_INFO, message + arguments2);
+ return;
+ }
+
MDC.put(classNameProp, "");
- String serviceName = MDC.get(MDC_SERVICE_NAME);
- metricsLogger.info(MessageCodes.RULE_METRICS_INFO, serviceName, "" + arg0);
+ metricsLogger.info(message, arguments);
}
/**
@@ -1166,13 +1229,13 @@ public class PolicyLogger {
* @param arguments the messages
*/
private static String getNormalizedStackTrace(Throwable throwable, String... arguments) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
+ var sw = new StringWriter();
+ var pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
String newStValue = sw.toString().replace('|', '!').replace("\n", " - ");
int curSize = arguments == null ? 0 : arguments.length;
- StringBuilder newArgument = new StringBuilder();
- for (int i = 0; i < curSize; i++) {
+ var newArgument = new StringBuilder();
+ for (var i = 0; i < curSize; i++) {
newArgument.append(arguments[i]);
newArgument.append(":");
}
@@ -1186,12 +1249,12 @@ public class PolicyLogger {
private static void startCleanUp() {
if (!isEventTrackerRunning) {
- ttrcker = new EventTrackInfoHandler();
+ var ttrcker = new EventTrackInfoHandler();
timer = new Timer(true);
timer.scheduleAtFixedRate(ttrcker, timerDelayTime, checkInterval);
- debugLogger.info("EventTrackInfoHandler begins! : " + new Date());
+ debugLogger.info("EventTrackInfoHandler begins! : {}", new Date());
} else {
- debugLogger.info("Timer is still running : " + new Date());
+ debugLogger.info("Timer is still running : {}", new Date());
}
}
@@ -1205,9 +1268,9 @@ public class PolicyLogger {
if (isEventTrackerRunning && timer != null) {
timer.cancel();
timer.purge();
- debugLogger.info("Timer stopped: " + new Date());
+ debugLogger.info("Timer stopped: {}", new Date());
} else {
- debugLogger.info("Timer was already stopped : " + new Date());
+ debugLogger.info("Timer was already stopped : {}", new Date());
}
isEventTrackerRunning = false;
@@ -1219,7 +1282,7 @@ public class PolicyLogger {
*/
public static LoggerType init(Properties properties) {
- Properties loggerProperties = getLoggerProperties(properties);
+ var loggerProperties = getLoggerProperties(properties);
// fetch and verify definitions of some properties
try {
@@ -1241,7 +1304,7 @@ public class PolicyLogger {
stopCheckPoint = getIntProp(loggerProperties, "stop.check.point", stopCheckPoint);
component = loggerProperties.getProperty("policy.component", "DROOLS");
- debugLogger.info("component: " + component);
+ debugLogger.info("component: {}", component);
return detmLoggerType(loggerProperties);
@@ -1261,9 +1324,9 @@ public class PolicyLogger {
}
private static int getIntProp(Properties properties, String propName, int defaultValue) {
- final int propValue = Integer.parseInt(properties.getProperty(propName, String.valueOf(defaultValue)));
+ final var propValue = Integer.parseInt(properties.getProperty(propName, String.valueOf(defaultValue)));
- debugLogger.info(propName + " value: " + propValue);
+ debugLogger.info("{} value: {}", propName, propValue);
if (propValue > 0) {
return propValue;
@@ -1276,7 +1339,7 @@ public class PolicyLogger {
ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
- errorLogger.error("failed to get the " + propName + ", so use its default value: " + defaultValue);
+ errorLogger.error("failed to get the {}, so use its default value: {}", propName, defaultValue);
return defaultValue;
}
}
@@ -1296,7 +1359,7 @@ public class PolicyLogger {
final String propValue = properties.getProperty(propName, defaultValue);
if (!StringUtils.isBlank(propValue)) {
- debugLogger.info(propName + " level: " + propValue);
+ debugLogger.info("{} level: {}", propName, propValue);
}
setter.accept(propValue);
@@ -1306,31 +1369,27 @@ public class PolicyLogger {
final String propValue = properties.getProperty(propName, "ON");
if (Level.OFF.toString().equalsIgnoreCase(propValue)) {
- debugLogger.info(propName + " level: " + propValue);
+ debugLogger.info("{} level: {}", propName, propValue);
}
setter.accept(propValue);
}
private static void setOverrideLogbackLevels(Properties loggerProperties) {
- final String overrideLogbackLevel = loggerProperties.getProperty("override.logback.level.setup");
+ final var overrideLogbackLevelText = loggerProperties.getProperty("override.logback.level.setup");
- if (!StringUtils.isBlank(overrideLogbackLevel)) {
- isOverrideLogbackLevel = "TRUE".equalsIgnoreCase(overrideLogbackLevel);
+ if (!StringUtils.isBlank(overrideLogbackLevelText)) {
+ overrideLogbackLevel = "TRUE".equalsIgnoreCase(overrideLogbackLevelText);
}
}
private static LoggerType detmLoggerType(Properties loggerProperties) {
final String loggerTypeProp = loggerProperties.getProperty("logger.type", LoggerType.EELF.toString());
- debugLogger.info("loggerType value: " + loggerTypeProp);
+ debugLogger.info("loggerType value: {}", loggerTypeProp);
switch (loggerTypeProp.toUpperCase()) {
case "EELF":
return LoggerType.EELF;
-
- case "LOG4J":
- return LoggerType.LOG4J;
-
case "SYSTEMOUT":
return LoggerType.SYSTEMOUT;
@@ -1339,28 +1398,26 @@ public class PolicyLogger {
}
}
-
/**
- * 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.
+ * Sets server information to MDC.
*/
- public static void setOverrideLogbackLevel(boolean odl) {
-
- isOverrideLogbackLevel = odl;
-
+ public static void setServerInfo(String serverHost, String serverPort) {
+ MDC.put(SERVER_NAME, serverHost + ":" + serverPort);
}
/**
- * Sets server information to MDC.
+ * Sets error category, code and description.
*/
- public static void setServerInfo(String serverHost, String serverPort) {
- MDC.put(SERVER_NAME, serverHost + ":" + serverPort);
+ private static void setErrorCode(MessageCodes errcode) {
+ MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
+ if (ErrorCodeMap.getErrorCodeInfo(errcode) != null) {
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(errcode).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(errcode).getErrorDesc());
+ } else {
+ MDC.put(ERROR_CODE,
+ ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_UNKNOWN).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION,
+ ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_UNKNOWN).getErrorDesc());
+ }
}
}