X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Flogging%2Faop%2FEPEELFLoggerAdvice.java;h=18fb5027ba7f5ddff471ac0df23750891353e320;hb=24608a9e1450c409dc3870440d29e91cc3a26bb9;hp=c1127758f3cc119a056b7c32dbc39ff104f08ac6;hpb=fadf84a4a76f7501e7dad2f426cdf4603304baad;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java index c1127758..18fb5027 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAdvice.java @@ -33,11 +33,12 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalapp.portal.logging.aop; import java.net.InetAddress; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.UUID; @@ -64,11 +65,11 @@ public class EPEELFLoggerAdvice { private EELFLoggerDelegate adviceLogger = EELFLoggerDelegate.getLogger(EPEELFLoggerAdvice.class); /** - * DateTime Format according to the ECOMP Application Logging Guidelines. + * DateTime Format according to the ONAP Application Logging Guidelines. */ /** - * @return Current date and time in the format specified by the ECOMP + * @return Current date and time in the format specified by the ONAP * Application Logging Guidelines. */ public static String getCurrentDateTimeUTC() { @@ -104,7 +105,7 @@ public class EPEELFLoggerAdvice { String className = ""; if (passOnArgs.length > 0 && passOnArgs[0] != null) className = passOnArgs[0].toString(); - String methodName = ""; + String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE; if (passOnArgs.length > 1 && passOnArgs[1] != null) methodName = passOnArgs[1].toString(); @@ -112,7 +113,7 @@ public class EPEELFLoggerAdvice { MDC.put(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC()); MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE); MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, methodName); - if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null || MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){ + 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); } @@ -149,7 +150,7 @@ public class EPEELFLoggerAdvice { if (passOnArgs.length > 0 && passOnArgs[0] != null) className = passOnArgs[0].toString(); // Method Name - String methodName = ""; + String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE; if (passOnArgs.length > 1 && passOnArgs[1] != null) methodName = passOnArgs[1].toString(); @@ -160,6 +161,14 @@ public class EPEELFLoggerAdvice { if (MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == null || MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == "") MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_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); + } + MDC.put(EPCommonSystemProperties.PARTNER_NAME, "Unknown"); + MDC.put(Configuration.MDC_SERVICE_NAME, EPCommonSystemProperties.ECOMP_PORTAL_BE); + MDC.put(EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, MDC.get(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP)); @@ -173,7 +182,7 @@ public class EPEELFLoggerAdvice { if (securityEventType != null && args.length > 0 && args[0] != null && args[0] instanceof HttpServletRequest && securityEventType == SecurityEventTypeEnum.INCOMING_REST_MESSAGE && (MDC.get(EPCommonSystemProperties.FULL_URL) == null - || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) { + || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) { HttpServletRequest req = (HttpServletRequest) args[0]; this.setHttpRequestBasedDefaultsIntoGlobalLoggingContext(req, securityEventType, methodName); } @@ -308,13 +317,12 @@ public class EPEELFLoggerAdvice { MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId); // Load user agent into MDC context, if available. - String accessingClient = "Unknown"; - accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME); + String accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME); + accessingClient = (accessingClient == null || accessingClient.trim().length()==0)?"Unknown":accessingClient; if (accessingClient != null && accessingClient.trim().length()==0 && (accessingClient.contains("Mozilla") || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) { accessingClient = EPCommonSystemProperties.ECOMP_PORTAL_FE; - }else if(accessingClient==null || accessingClient.isEmpty()) - accessingClient = "Unknown"; + } MDC.put(EPCommonSystemProperties.PARTNER_NAME, accessingClient); // Load loginId into MDC context. @@ -333,7 +341,8 @@ public class EPEELFLoggerAdvice { MDC.put(EPCommonSystemProperties.FULL_URL, EPCommonSystemProperties.UNKNOWN); MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTP); restURL = UserUtils.getFullURL(req); - if (restURL != null && restURL != "") { + //if (restURL != null && restURL != "") { + if (restURL != null && restURL.trim().length()>0) { MDC.put(EPCommonSystemProperties.FULL_URL, restURL); if (restURL.toLowerCase().contains("https")) { MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTPS); @@ -341,9 +350,11 @@ public class EPEELFLoggerAdvice { } // Rest Path - MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod); + MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); String restPath = req.getServletPath(); - if (restPath != null && !restPath.isEmpty()) { + //if (restPath != null && restPath != "") { + if (restPath != null && restPath.trim().length()>0) { + MDC.put(Configuration.MDC_SERVICE_NAME, restPath); } @@ -360,7 +371,7 @@ public class EPEELFLoggerAdvice { MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, "search"); } } else { - MDC.put(Configuration.MDC_SERVICE_NAME, (restMethod==null || restMethod.isEmpty()) ? "Unknown" : restMethod); + MDC.put(Configuration.MDC_SERVICE_NAME, restMethod); MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE); } @@ -398,4 +409,5 @@ public class EPEELFLoggerAdvice { public String getInternalResponseCode() { return MDC.get(EPCommonSystemProperties.RESPONSE_CODE); } + }