summaryrefslogtreecommitdiffstats
path: root/common-logging/src/main/java
diff options
context:
space:
mode:
authorJoseph Chou <jc2555@att.com>2020-04-08 17:45:38 -0400
committerJoseph Chou <jc2555@att.com>2020-04-10 12:27:47 -0400
commit8ed1d1c28fbf0e95e86f061f50bb362265ca51de (patch)
treee12e0c2fd5fe3ad4f0abc6ffac27819a1cc45168 /common-logging/src/main/java
parenta2ca5ed5782f32ca54d14ffde2cbcfa0e4c3fea3 (diff)
Update common-logging for log enhancement work
Resolve missing error code, add marker/mdc for audit/metrics Change-Id: I490b17aac86f3b63df43e267a5dbe1d1588e5fdf Issue-ID: POLICY-2478 Signed-off-by: Joseph Chou <jc2555@att.com>
Diffstat (limited to 'common-logging/src/main/java')
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java32
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java3
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java76
3 files changed, 58 insertions, 53 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
index fab0415b..32bb6fec 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 2017-2018 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.
@@ -24,6 +24,13 @@ import java.util.EnumMap;
/**
* ErrorCodeMap contains a HashMap of ErrorCodeInfo (error code and error description).
+ * Standard error code:
+ * 100 – permission errors
+ * 200 – availability errors
+ * 300 – data errors
+ * 400 – schema errors
+ * 500 – business process errors
+ * 900 – unknown errors
*/
public class ErrorCodeMap {
@@ -31,41 +38,42 @@ public class ErrorCodeMap {
private static final String CHECK_ERROR_MESSAGE = " Please check the error message for detail information";
- private static final String ERROR_PERMISSIONS = "POLICY-100E";
+ private static final String ERROR_PERMISSIONS = "100";
private static final String ERROR_PERMISSIONS_DESCRIPTION = "This is a Permissions Error." + CHECK_ERROR_MESSAGE;
- private static final String ERROR_SCHEMA_INVALID = "POLICY-400E";
+ private static final String ERROR_SCHEMA_INVALID = "400";
private static final String ERROR_SCHEMA_INVALID_DESCRIPTION = "This is an Invalid Schema Error."
+ CHECK_ERROR_MESSAGE;
- private static final String UPDATE_ERROR = "POLICY-502E";
+
+ private static final String UPDATE_ERROR = "300";
private static final String UPDATE_ERROR_DESCRIPTION = "This is an updating error." + CHECK_ERROR_MESSAGE;
- private static final String EXCEPTION_ERROR_CODE = "POLICY-503E";
+ private static final String EXCEPTION_ERROR_CODE = "500";
private static final String EXCEPTION_ERROR_DESCRIPTION = "This is an exception error message during the process."
+ CHECK_ERROR_MESSAGE;
- private static final String MISS_PROPERTY_ERROR = "POLICY-504E";
+ private static final String MISS_PROPERTY_ERROR = "300";
private static final String MISS_PROPERTY_ERROR_DESCRIPTION = "This is an error of missing properties."
+ CHECK_ERROR_MESSAGE;
- private static final String GENERAL_ERROR_CODE = "POLICY-515E";
+ private static final String GENERAL_ERROR_CODE = "500";
private static final String GENERAL_ERROR_DESCRIPTION = "This is a general error message during the process."
+ CHECK_ERROR_MESSAGE;
- private static final String ERROR_SYSTEM_ERROR = "POLICY-516E";
+ private static final String ERROR_SYSTEM_ERROR = "200";
private static final String ERROR_SYSTEM_ERROR_DESCRIPTION = "This is a System Error." + CHECK_ERROR_MESSAGE;
- private static final String ERROR_DATA_ISSUE = "POLICY-517E";
+ private static final String ERROR_DATA_ISSUE = "300";
private static final String ERROR_DATA_ISSUE_DESCRIPTION = "This is a Data Issue Error." + CHECK_ERROR_MESSAGE;
- private static final String ERROR_PROCESS_FLOW = "POLICY-518E";
+ private static final String ERROR_PROCESS_FLOW = "500";
private static final String ERROR_PROCESS_FLOW_DESCRIPTION = "This is a Process Flow Error." + CHECK_ERROR_MESSAGE;
- private static final String ERROR_UNKNOWN = "POLICY-519E";
+ private static final String ERROR_UNKNOWN = "900";
private static final String ERROR_UNKNOWN_DESCRIPTION = "This is an Unknown Error." + CHECK_ERROR_MESSAGE;
- private static final String ERROR_AUDIT = "POLICY-520E";
+ private static final String ERROR_AUDIT = "300";
private static final String ERROR_AUDIT_DESCRIPTION = "This is an audit Error." + CHECK_ERROR_MESSAGE;
static {
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java
index 8d2031db..47c027c2 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/OnapConfigProperties.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-Logging
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -80,6 +80,7 @@ public class OnapConfigProperties {
public static final String SERVER_NAME = "ServerName";
+ public static final String INVOCATION_ID = "InvocationID";
private OnapConfigProperties() {
// do nothing
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
index 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());
+ }
+ }
}