2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.logging.filter.base;
23 import java.util.UUID;
25 import org.aspectj.lang.ProceedingJoinPoint;
26 import org.onap.logging.ref.slf4j.ONAPLogConstants;
29 public abstract class AbstractMDCSetupAspect extends MDCSetup {
31 public abstract void logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable;
33 protected void setupMDC(String methodName) {
37 String partnerName = getProperty(Constants.Property.PARTNER_NAME);
38 MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, UUID.randomUUID().toString());
39 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
40 MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, UUID.randomUUID().toString());
41 MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, partnerName);
42 MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, Constants.DefaultValues.UNKNOWN);
43 MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, methodName);
46 MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
47 logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
48 } catch (Exception e) {
49 logger.warn("Error in ScheduledTasksMDCSetup: {}", e.getMessage());
53 protected void exitAndClearMDC() {
58 logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
59 } catch (Exception e) {
60 logger.warn("Error in ScheduledTasksMDCSetup clear MDC: {}", e.getMessage());
65 protected void setStatusCode() {
66 String currentStatusCode = MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
67 if (currentStatusCode == null || !currentStatusCode.equals(ONAPLogConstants.ResponseStatus.ERROR.toString())) {
68 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.COMPLETE.toString());
72 public void errorMDCSetup(ErrorCode errorCode, String errorDescription) {
73 MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(errorCode.getValue()));
74 MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, errorDescription);
75 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());