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.java76
1 files changed, 36 insertions, 40 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 c32cf0bb..9e5fd5a6 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
@@ -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;
@@ -55,6 +56,7 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
import java.util.Timer;
import java.util.UUID;
@@ -558,11 +560,7 @@ public class PolicyLogger {
*/
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());
-
- }
+ setErrorCode(MessageCodes.GENERAL_ERROR);
errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
}
@@ -573,13 +571,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);
}
@@ -590,13 +582,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);
}
@@ -609,13 +595,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);
}
@@ -631,13 +611,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);
}
@@ -650,13 +624,7 @@ 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);
}
@@ -738,7 +706,9 @@ public class PolicyLogger {
* @param arg0 the message
*/
public static void audit(String className, 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, className);
auditLogger.info("" + arg0);
}
@@ -749,7 +719,9 @@ 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);
}
@@ -1064,6 +1036,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);
}
@@ -1082,6 +1055,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);
}
@@ -1119,6 +1093,8 @@ public class PolicyLogger {
* @param arg0 the message
*/
public static void metrics(String arg0) {
+ 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);
}
@@ -1130,6 +1106,8 @@ public class PolicyLogger {
*/
public static void metrics(String className, Object arg0) {
seTimeStamps();
+ MDC.put(INVOCATION_ID, MDC.get(MDC_KEY_REQUEST_ID));
+ MDC.put(RESPONSE_CODE, "0");
MDC.put(classNameProp, className);
String serviceName = MDC.get(MDC_SERVICE_NAME);
metricsLogger.info(MessageCodes.RULE_METRICS_INFO, serviceName, "" + arg0);
@@ -1142,6 +1120,8 @@ public class PolicyLogger {
*/
public static void metrics(Object arg0) {
seTimeStamps();
+ 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);
@@ -1361,4 +1341,20 @@ public class PolicyLogger {
public static void setServerInfo(String serverHost, String serverPort) {
MDC.put(SERVER_NAME, serverHost + ":" + serverPort);
}
+
+ /**
+ * Sets error category, code and description.
+ */
+ 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());
+ }
+ }
}