X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=vid-app-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvid%2Flogging%2FVidLoggerAspect.java;h=f87297c3730bd0f8642162004248a1761e18a3b2;hb=e8d29ab5e3775472f59a4997fa3a5df9319de306;hp=309ead40c395429473d6f6343b20d2e343127817;hpb=f09e8d114804e4237e79f27ed492835ecb1b17b0;p=vid.git diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java index 309ead40c..f87297c37 100644 --- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java +++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java @@ -32,6 +32,7 @@ import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.service.AppService; @@ -39,6 +40,7 @@ import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.web.support.UserUtils; import org.onap.vid.controller.ControllersUtils; import org.onap.vid.utils.SystemPropertiesWrapper; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -87,9 +89,10 @@ public class VidLoggerAspect { Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()}; Object[] returnArgs = advice.before(securityEventType, fabricateArgsWithNull(), passOnArgs); - fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequestOrNull(joinPoint), + HttpServletRequest httpServletRequest = httpServletRequestOrNull(joinPoint); + fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, joinPoint.getSignature().getDeclaringType().getName()); - + addRequestIdToMdcForMetricFilter(httpServletRequest); fixServerFqdnInMDC(); //Execute the actual method @@ -108,6 +111,14 @@ public class VidLoggerAspect { return result; } + //prepare MDC for org.onap.logging.filter.base.AbstractMetricLogFilter + private void addRequestIdToMdcForMetricFilter(HttpServletRequest httpServletRequest) { + if (httpServletRequest!=null) { + String requestId = UserUtils.getRequestId(httpServletRequest); + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId); + } + } + // Set the status code into MDC *before* the metrics log is written by advice.after() private void fixStatusCodeInMDC(String restStatus) { EELFLoggerDelegate.mdcPut(SystemProperties.STATUS_CODE, restStatus); @@ -155,6 +166,7 @@ public class VidLoggerAspect { String loginId = controllersUtils.extractUserId(httpServletRequest); logger.setRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, appName, requestId, loginId); + } }