summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java')
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java74
1 files changed, 63 insertions, 11 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
index 55a27837..6a5fe469 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
@@ -37,14 +37,24 @@
*/
package org.onap.portalsdk.core.logging.aspect;
+import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+
+import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.exception.SessionExpiredException;
+import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
import org.onap.portalsdk.core.logging.format.AuditLogFormatter;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.logging.logic.LoggerProperties;
import org.onap.portalsdk.core.service.AppService;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
@@ -94,21 +104,39 @@ public class EELFLoggerAdvice {
methodName = passOnArgs[1].toString();
}
- String appName = appService.getDefaultAppName();
+ String appName ="";
if (appName == null || appName == "") {
appName = SystemProperties.SDK_NAME;
}
-
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
+ else {
+ appName = appService.getDefaultAppName();
+ }
// Initialize Request defaults only for controller methods.
+ MDC.put(MDC_SERVICE_NAME, SystemProperties.getProperty(SystemProperties.APPLICATION_NAME));
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ MDC.put(MDC_INSTANCE_UUID, LoggerProperties.getProperty(LoggerProperties.INSTANCE_UUID));
MDC.put(className + methodName + SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
+ MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
+ MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
MDC.put(SystemProperties.TARGET_ENTITY, appName + "_BE");
MDC.put(SystemProperties.TARGET_SERVICE_NAME, methodName);
+ MDC.put(SystemProperties.STATUS_CODE, "INPROGRESS");
+ if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
+ String requestId = UUID.randomUUID().toString();
+ MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
+ }
+ MDC.put(SystemProperties.PARTNER_NAME, "Unknown");
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
+
if (securityEventType != null) {
MDC.put(className + methodName + SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
+ MDC.put(SystemProperties.CUSTOM_FIELD1, "ENTRY");
+ HttpServletRequest req = null;
if (args[0] != null && args[0] instanceof HttpServletRequest) {
- HttpServletRequest req = (HttpServletRequest) args[0];
+ req = (HttpServletRequest) args[0];
String requestId = UserUtils.getRequestId(req);
String loginId = "";
User user = UserUtils.getUserSession(req);
@@ -117,7 +145,17 @@ public class EELFLoggerAdvice {
}
logger.setRequestBasedDefaultsIntoGlobalLoggingContext(req, appName, requestId, loginId);
}
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
+ this.calculateDateTimeDifference(MDC.get(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
+ MDC.get(SystemProperties.AUDITLOG_END_TIMESTAMP));
+
+ }else {
+ MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
+ this.calculateDateTimeDifference(MDC.get(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP),MDC.get(SystemProperties.METRICSLOG_END_TIMESTAMP));
+ MDC.put(SystemProperties.CUSTOM_FIELD1, "INVOKE");
}
+ MDC.put(SystemProperties.CUSTOM_FIELD2, " InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID));
+ logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is started.");
logger.debug(EELFLoggerDelegate.debugLogger, "{} was invoked.", methodName);
} catch (Exception e) {
adviceLogger.error(EELFLoggerDelegate.errorLogger, "before failed", e);
@@ -147,8 +185,6 @@ public class EELFLoggerAdvice {
methodName = passOnArgs[1].toString();
}
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
-
String appName = appService.getDefaultAppName();
if (appName == null || appName == "") {
appName = SystemProperties.SDK_NAME;
@@ -163,6 +199,15 @@ public class EELFLoggerAdvice {
MDC.put(SystemProperties.TARGET_ENTITY, appName + "_BE");
}
+ if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
+ String requestId = UUID.randomUUID().toString();
+ MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
+ }
+
+ if (MDC.get(SystemProperties.PARTNER_NAME) == null|| MDC.get(SystemProperties.PARTNER_NAME).isEmpty()){
+ MDC.put(SystemProperties.PARTNER_NAME, "Unknown");
+ }
+ MDC.put(MDC_SERVICE_NAME, SystemProperties.getProperty(SystemProperties.APPLICATION_NAME));
MDC.put(SystemProperties.STATUS_CODE, result);
@@ -172,9 +217,8 @@ public class EELFLoggerAdvice {
this.calculateDateTimeDifference(MDC.get(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP),
MDC.get(SystemProperties.METRICSLOG_END_TIMESTAMP));
-
- logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is completed.");
- logger.debug(EELFLoggerDelegate.debugLogger, "Finished executing " + methodName + ".");
+ MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
if (securityEventType != null) {
@@ -183,7 +227,8 @@ public class EELFLoggerAdvice {
MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
this.calculateDateTimeDifference(MDC.get(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
MDC.get(SystemProperties.AUDITLOG_END_TIMESTAMP));
-
+ MDC.put(SystemProperties.CUSTOM_FIELD1, "EXIT");
+
this.logSecurityMessage(logger, securityEventType, result, methodName);
// clear when finishes audit logging
@@ -199,8 +244,12 @@ public class EELFLoggerAdvice {
MDC.remove(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
MDC.remove(SystemProperties.AUDITLOG_END_TIMESTAMP);
}else{
- MDC.put(SystemProperties.STATUS_CODE, "COMPLETE");
+ MDC.put(SystemProperties.CUSTOM_FIELD1, "INVOKE-RETURN");
}
+ MDC.put(SystemProperties.STATUS_CODE, "COMPLETE");
+ MDC.put(SystemProperties.CUSTOM_FIELD2, " InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID));
+ logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is completed.");
+ logger.debug(EELFLoggerDelegate.debugLogger, "Finished executing " + methodName + ".");
MDC.remove(className + methodName + SystemProperties.METRICSLOG_BEGIN_TIMESTAMP);
MDC.remove(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP);
@@ -209,6 +258,9 @@ public class EELFLoggerAdvice {
MDC.remove(SystemProperties.TARGET_ENTITY);
MDC.remove(SystemProperties.TARGET_SERVICE_NAME);
MDC.remove(SystemProperties.STATUS_CODE);
+ MDC.remove(MDC_SERVICE_NAME);
+ MDC.remove(SystemProperties.CUSTOM_FIELD1);
+ MDC.remove(SystemProperties.CUSTOM_FIELD2);
} catch (Exception e) {
adviceLogger.error(EELFLoggerDelegate.errorLogger, "after failed", e);