summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-logger
diff options
context:
space:
mode:
authorKishore Reddy Dwaram <kishore.reddy.dwaram@att.com>2020-10-02 16:55:46 -0400
committerKishore Reddy Dwaram <kishore.reddy.dwaram@att.com>2020-10-02 16:56:40 -0400
commit5510fd481ffe19a3acefdccc8a0eb4847e5d4b57 (patch)
tree0ec522b124565b916bf01f02a0c87956d15cabe9 /ecomp-sdk/epsdk-logger
parent00bec2a1bf1e58d3c6ce385d99f720ef7ddf53ac (diff)
Updated code for audit and error logs
Issue-ID: PORTAL-1008 Signed-off-by: Kishore Reddy Dwaram <kishore.reddy.dwaram@att.com> Change-Id: I6cbde4a6418e3fc2ae7140fa72e08263988bb293
Diffstat (limited to 'ecomp-sdk/epsdk-logger')
-rw-r--r--ecomp-sdk/epsdk-logger/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java55
1 files changed, 39 insertions, 16 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 21290f59..b28bcf5a 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
@@ -113,23 +113,12 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
public void logWrite(EELFLogger logger, Level level, String msg, Throwable th, Object... arguments) {
MDC.put(LoggerProperties.MDC_CLASS_NAME, className);
setGlobalLoggingContext();
- String requestId = null;
if (MDC.get(MDC_KEY_REQUEST_ID) == null||MDC.get(MDC_KEY_REQUEST_ID).isEmpty()){
- requestId = UUID.randomUUID().toString();
+ String requestId = UUID.randomUUID().toString();
MDC.put(MDC_KEY_REQUEST_ID, requestId);
}
-
if ( logger == errorLogger) {
- if(MDC.get(LoggerProperties.ERROR_CATAGORY) == null||MDC.get(LoggerProperties.ERROR_CATAGORY).isEmpty()) {
- MDC.put(LoggerProperties.ERROR_CATAGORY, ErrorSeverityEnum.ERROR.name());
- }
- if(MDC.get(LoggerProperties.ERROR_CODE) == null) {
- MDC.put(LoggerProperties.ERROR_CODE, "900");
- }
- if(MDC.get(LoggerProperties.ERROR_DESCRIPTION) == null) {
- MDC.put(LoggerProperties.ERROR_DESCRIPTION, "Exception");
- }
-
+ validateErrorLogFields();
}
if(MDC.get(LoggerProperties.PARTNER_NAME) == null) {
@@ -141,9 +130,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
}
if ( logger == auditLogger) {
- 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);
+ validateAuditLogFields();
}
if (logger.isErrorEnabled()) {
@@ -169,6 +156,39 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
MDC.remove(LoggerProperties.PARTNER_NAME);
}
+
+ /**
+ * Mandatory error logs fields
+ *
+ */
+ public void validateErrorLogFields() {
+ if(MDC.get(LoggerProperties.ERROR_CATAGORY) == null||MDC.get(LoggerProperties.ERROR_CATAGORY).isEmpty()) {
+ MDC.put(LoggerProperties.ERROR_CATAGORY, ErrorSeverityEnum.ERROR.name());
+ }
+ if(MDC.get(LoggerProperties.ERROR_CODE) == null) {
+ MDC.put(LoggerProperties.ERROR_CODE, "900");
+ }
+ if(MDC.get(LoggerProperties.ERROR_DESCRIPTION) == null) {
+ MDC.put(LoggerProperties.ERROR_DESCRIPTION, "Exception");
+ }
+ }
+
+ /**
+ * Mandatory Audit logs fields
+ *
+ */
+ public void validateAuditLogFields() {
+ if (MDC.get(LoggerProperties.AUDITLOG_END_TIMESTAMP) == null||MDC.get(LoggerProperties.AUDITLOG_END_TIMESTAMP).isEmpty() ) {
+ MDC.put(LoggerProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
+ }
+ this.calculateDateTimeDifference(MDC.get(LoggerProperties.AUDITLOG_BEGIN_TIMESTAMP), MDC.get(LoggerProperties.AUDITLOG_END_TIMESTAMP));
+ if(MDC.get(LoggerProperties.CUSTOM_FIELD1) == null||MDC.get(LoggerProperties.CUSTOM_FIELD1).isEmpty()) {
+ MDC.put(LoggerProperties.CUSTOM_FIELD1, "EXIT");
+ }
+ if(MDC.get(LoggerProperties.CUSTOM_FIELD2) == null||MDC.get(LoggerProperties.CUSTOM_FIELD2).isEmpty()) {
+ MDC.put(LoggerProperties.CUSTOM_FIELD2, "InvocationID=" + MDC.get(MDC_KEY_REQUEST_ID));
+ }
+ }
/**
@@ -385,6 +405,7 @@ public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
errorLogger.error(resolution);
}
} catch (Exception e) {
+ validateErrorLogFields();
errorLogger.error("logEcompError failed " + e.getMessage());
} finally {
MDC.remove(LoggerProperties.ERROR_CODE);
@@ -423,6 +444,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) {
+ validateErrorLogFields();
errorLogger.error("setGlobalLoggingContext failed " + e.getMessage());
}
}
@@ -524,6 +546,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) {
+ validateErrorLogFields();
errorLogger.error("calculateDateTimeDifference failed " + e.getMessage());
}
}