summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxg353y <xg353y@intl.att.com>2019-01-16 15:42:30 +0100
committerxg353y <xg353y@intl.att.com>2019-01-16 15:42:30 +0100
commit2fb7aa6751140b4d7070bff4d18901ae10061e04 (patch)
treee49c050d2042b1f33cceb4fdebbb5e036e0ec90a
parent5dea22255fc131d5c2b0348986bfc75c56d17097 (diff)
Clear MDC variables
Clear the MDC variables at the beginning and the end of the API calls. Issue-ID: CLAMP-271 Change-Id: I32504b00c812a4441ba1e4548bb7f42cf2894993 Signed-off-by: xg353y <xg353y@intl.att.com>
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsHealthcheckService.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/util/LoggingUtils.java3
2 files changed, 8 insertions, 0 deletions
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsHealthcheckService.java b/src/main/java/org/onap/clamp/clds/service/CldsHealthcheckService.java
index a017d54b0..c25e6e7ac 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsHealthcheckService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsHealthcheckService.java
@@ -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);
}
}
diff --git a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
index 759edb1d9..300d60663 100644
--- a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
+++ b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
@@ -176,6 +176,7 @@ public class LoggingUtils {
* @return this.
*/
public void entering(HttpServletRequest request, String serviceName) {
+ MDC.clear();
checkNotNull(request);
// Extract MDC values from standard HTTP headers.
final String requestID = defaultToUUID(request.getHeader(ONAPLogConstants.Headers.REQUEST_ID));
@@ -205,6 +206,8 @@ public class LoggingUtils {
if (serviceName == null ||
serviceName.equalsIgnoreCase(EMPTY_MESSAGE)) {
MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI());
+ } else {
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName);
}
this.mLogger.info(ONAPLogConstants.Markers.ENTRY);