summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-logger
diff options
context:
space:
mode:
authorKishore Reddy Dwaram <kishore.reddy.dwaram@att.com>2020-09-30 18:08:36 -0400
committerKishore Reddy Dwaram <kishore.reddy.dwaram@att.com>2020-10-01 12:42:24 -0400
commit00bec2a1bf1e58d3c6ce385d99f720ef7ddf53ac (patch)
tree9d4c78de6749c5598a17700b7472b78ad46853e6 /ecomp-sdk/epsdk-logger
parenta8618399833e9e2c2cfdd214058234a1395f8361 (diff)
Updated error logger pattern and code changes to handle error logs
Issue-ID: PORTAL-1008 Signed-off-by: Kishore Reddy Dwaram <kishore.reddy.dwaram@att.com> Change-Id: Icca867e3e57708a5aac49eff60248af53522e1f4
Diffstat (limited to 'ecomp-sdk/epsdk-logger')
-rw-r--r--ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java43
-rw-r--r--ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java2
2 files changed, 23 insertions, 22 deletions
diff --git a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
index 45eae6d4..21290f59 100644
--- a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
+++ b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
@@ -120,10 +120,9 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
}
if ( logger == errorLogger) {
- if(MDC.get(LoggerProperties.MDC_CLASS_NAME) == null) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
+ if(MDC.get(LoggerProperties.ERROR_CATAGORY) == null||MDC.get(LoggerProperties.ERROR_CATAGORY).isEmpty()) {
+ MDC.put(LoggerProperties.ERROR_CATAGORY, ErrorSeverityEnum.ERROR.name());
}
- MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.ERROR.name());
if(MDC.get(LoggerProperties.ERROR_CODE) == null) {
MDC.put(LoggerProperties.ERROR_CODE, "900");
}
@@ -142,7 +141,6 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
}
if ( logger == auditLogger) {
- MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
this.calculateDateTimeDifference(MDC.get(LoggerProperties.AUDITLOG_BEGIN_TIMESTAMP), MDC.get(LoggerProperties.AUDITLOG_END_TIMESTAMP));
MDC.put(LoggerProperties.CUSTOM_FIELD1, "EXIT");
MDC.put(LoggerProperties.CUSTOM_FIELD2, "InvocationID=" + requestId);
@@ -153,23 +151,26 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
} else {
logger.log(level, msg, th, arguments);
}
-
- if ( logger == errorLogger) {
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- MDC.remove(LoggerProperties.ERROR_CATAGORY);
- MDC.remove(LoggerProperties.ERROR_CODE);
- MDC.remove(LoggerProperties.ERROR_DESCRIPTION);
- }
-
- if(logger == auditLogger) {
- MDC.remove(LoggerProperties.MDC_CLASS_NAME);
- MDC.remove(LoggerProperties.CUSTOM_FIELD1);
- MDC.remove(LoggerProperties.CUSTOM_FIELD2);
- }
+ tearDownMDC();
+ }
+
+ /**
+ * remove the logger context.
+ */
+ public void tearDownMDC() {
+ MDC.remove(LoggerProperties.ERROR_CATAGORY);
+ MDC.remove(LoggerProperties.ERROR_CODE);
+ MDC.remove(LoggerProperties.ERROR_DESCRIPTION);
+ MDC.remove(LoggerProperties.MDC_TIMER);
+ MDC.remove(LoggerProperties.CUSTOM_FIELD1);
+ MDC.remove(LoggerProperties.CUSTOM_FIELD2);
MDC.remove(MDC_KEY_REQUEST_ID);
-
+ MDC.remove(LoggerProperties.STATUS_CODE);
+ MDC.remove(LoggerProperties.PARTNER_NAME);
+
}
+
/**
* Logs a message at the lowest level: trace.
*
@@ -384,7 +385,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
errorLogger.error(resolution);
}
} catch (Exception e) {
- errorLogger.error("logEcompError failed", e);
+ errorLogger.error("logEcompError failed " + e.getMessage());
} finally {
MDC.remove(LoggerProperties.ERROR_CODE);
MDC.remove(LoggerProperties.ERROR_DESCRIPTION);
@@ -422,7 +423,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
MDC.put(MDC_SERVICE_NAME, LoggerProperties.getPropertyValue(LoggerProperties.APP_NAME));
} catch (Exception e) {
- errorLogger.error("setGlobalLoggingContext failed", e);
+ errorLogger.error("setGlobalLoggingContext failed " + e.getMessage());
}
}
@@ -523,7 +524,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
String timeDifference = String.format("%d", endDate.getTime() - beginDate.getTime());
MDC.put(LoggerProperties.MDC_TIMER, timeDifference);
} catch (Exception e) {
- errorLogger.error("calculateDateTimeDifference failed", e);
+ errorLogger.error("calculateDateTimeDifference failed " + e.getMessage());
}
}
}
diff --git a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java
index 4287088b..003929e6 100644
--- a/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java
+++ b/ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/LoggerProperties.java
@@ -82,7 +82,7 @@ public class LoggerProperties {
public static final String USER_ATTRIBUTE_NAME = "user_attribute_name";
public static final String ALERT_SEVERITY = "AlertSeverity";
- public static final String ERROR_CATAGORY = "ErrorCatagory";
+ public static final String ERROR_CATAGORY = "ErrorCategory";
public static final String ERROR_CODE = "ErrorCode";
public static final String ERROR_DESCRIPTION = "ErrorDescription";
public static final String CUSTOM_FIELD1 = "CustomField1";