2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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.aai.aailog.logs;
23 import java.time.ZoneOffset;
24 import java.time.ZonedDateTime;
25 import java.time.format.DateTimeFormatter;
27 import org.onap.aai.logging.AaiElsErrorCode;
28 import org.onap.logging.filter.base.MDCSetup;
29 import org.onap.logging.ref.slf4j.ONAPLogConstants;
32 public class AaiDmaapMetricLog extends MDCSetup {
34 protected static final Logger logger = LoggerFactory.getLogger(AaiDmaapMetricLog.class);
35 private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
36 private static final String TARGET_ENTITY = "DMaaP";
38 public AaiDmaapMetricLog() {
39 if (MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN) == null) {
44 public void pre(String targetServiceName, String event, String transactionId, String serviceName) {
47 MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP,
48 ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
50 setElapsedTimeInvokeTimestamp();
51 MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, targetServiceName);
52 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
53 MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, TARGET_ENTITY);
54 if (transactionId != null && !(transactionId.isEmpty())) {
55 MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, transactionId);
57 if (serviceName != null && !(serviceName.isEmpty())) {
58 MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, serviceName);
60 setInvocationIdFromMDC();
61 logger.info(ONAPLogConstants.Markers.INVOKE, event);
63 } catch (Exception e) {
64 logger.warn("Error in AaiDmaapMetricLog pre", e.getMessage());
68 public void post(String responseCode, String errorDescription) {
72 setElapsedTimeInvokeTimestamp();
73 setResponseStatusCode(responseCode, errorDescription);
74 logger.info(INVOKE_RETURN, "InvokeReturn");
76 } catch (Exception e) {
77 logger.warn("Error in AaiDmaapMetricLog post", e.getMessage());
81 public void setResponseStatusCode(String aaiElsErrorCode, String errorDescription) {
83 if (AaiElsErrorCode.SUCCESS.equals(aaiElsErrorCode)) {
84 statusCode = ONAPLogConstants.ResponseStatus.COMPLETE.toString();
86 statusCode = ONAPLogConstants.ResponseStatus.ERROR.toString();
87 MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, aaiElsErrorCode);
88 MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, errorDescription);
90 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode);
91 MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, aaiElsErrorCode);