Merge "Clear MDC variables"
authorSébastien Determe <sebastien.determe@intl.att.com>
Thu, 17 Jan 2019 10:00:51 +0000 (10:00 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 17 Jan 2019 10:00:51 +0000 (10:00 +0000)
src/main/java/org/onap/clamp/clds/service/CldsHealthcheckService.java
src/main/java/org/onap/clamp/clds/util/LoggingUtils.java

index a017d54..c25e6e7 100644 (file)
@@ -29,6 +29,8 @@ import java.util.Date;
 import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CldsHealthCheck;
 import org.onap.clamp.clds.util.LoggingUtils;
+import org.onap.clamp.clds.util.ONAPLogConstants;
+import org.slf4j.event.Level;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -54,6 +56,7 @@ public class CldsHealthcheckService {
     public ResponseEntity<CldsHealthCheck> gethealthcheck() {
         CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
         Date startTime = new Date();
+        LoggingUtils util = new LoggingUtils(logger);
         LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check");
         LoggingUtils.setTimeContext(startTime, new Date());
         boolean healthcheckFailed = false;
@@ -74,8 +77,10 @@ public class CldsHealthcheckService {
         // audit log
         LoggingUtils.setTimeContext(startTime, new Date());
         if(healthcheckFailed) {
+            util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "Healthcheck failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
             return new ResponseEntity<>(cldsHealthCheck, HttpStatus.INTERNAL_SERVER_ERROR);
         } else {
+            util.exiting("200", "Healthcheck failed", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
             return new ResponseEntity<>(cldsHealthCheck, HttpStatus.OK);
         }
     }
index 759edb1..300d606 100644 (file)
@@ -176,6 +176,7 @@ public class LoggingUtils {
      * @return this.\r
      */\r
     public void entering(HttpServletRequest request, String serviceName) {\r
+        MDC.clear();\r
         checkNotNull(request);\r
         // Extract MDC values from standard HTTP headers.\r
         final String requestID = defaultToUUID(request.getHeader(ONAPLogConstants.Headers.REQUEST_ID));\r
@@ -205,6 +206,8 @@ public class LoggingUtils {
         if (serviceName == null ||\r
             serviceName.equalsIgnoreCase(EMPTY_MESSAGE)) {\r
             MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI());\r
+        } else {\r
+            MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName);\r
         }\r
 \r
         this.mLogger.info(ONAPLogConstants.Markers.ENTRY);\r