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=========================================================
19 * Modifications copyright (c) 2020 Nordix Foundation
20 * ================================================================================
22 package org.openecomp.sdc.common.log.elements;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
29 import org.openecomp.sdc.common.log.api.ILogConfiguration;
30 import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
31 import org.openecomp.sdc.common.log.enums.LogLevel;
32 import org.openecomp.sdc.common.log.enums.LogMarkers;
33 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
34 import org.openecomp.sdc.common.log.enums.StatusCode;
35 import org.slf4j.Logger;
36 import org.slf4j.MarkerFactory;
38 public class LoggerSupportability extends LoggerBase {
40 private static ArrayList<String> mandatoryFields = new ArrayList<>(Arrays.asList(
41 ILogConfiguration.MDC_SUPPORTABLITY_ACTION,
42 ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID,
43 ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION,
44 ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME,
45 ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID,
46 ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION,
47 ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE));
49 public LoggerSupportability(ILogFieldsHandler ecompLogFieldsHandler, Logger logger) {
50 super(ecompLogFieldsHandler, MarkerFactory.getMarker(LogMarkers.SUPPORTABILITY_MARKER.getText()),
54 public static LoggerSupportability getLogger(String className) {
55 return LoggerFactory.getMdcLogger(LoggerSupportability.class,
56 org.slf4j.LoggerFactory.getLogger(className));
59 public void log(LoggerSupportabilityActions action, Map<String, String> componentMetaData, StatusCode statusCode,
60 String message, Object... params) {
61 fillFieldsBeforeLogging(action, componentMetaData, statusCode);
62 super.log(LogLevel.INFO, message, params);
65 public void log(LoggerSupportabilityActions action, StatusCode statusCode, String message, Object... params) {
66 log(action, null, statusCode, message, params);
69 private void fillFieldsBeforeLogging(LoggerSupportabilityActions action, Map<String, String> componentMetaData,
70 StatusCode statusCode) {
72 if (componentMetaData != null) {
74 .setSupportablityCsarUUID(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID));
76 .setSupportablityCsarVersion(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION));
77 ecompLogFieldsHandler.setSupportablityComponentName(
78 componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME));
79 ecompLogFieldsHandler.setSupportablityComponentUUID(
80 componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID));
81 ecompLogFieldsHandler.setSupportablityComponentVersion(
82 componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION));
84 ecompLogFieldsHandler.setSupportablityAction(action.getName());
85 ecompLogFieldsHandler.setSupportablityStatusCode(statusCode.getStatusCode());
89 public LoggerSupportability clear() {
90 LogFieldsMdcHandler.getInstance().removeSupportablityAction();
91 LogFieldsMdcHandler.getInstance().removeSupportablityCsarUUID();
92 LogFieldsMdcHandler.getInstance().removeSupportablityCsarVersion();
93 LogFieldsMdcHandler.getInstance().removeSupportablityComponentName();
94 LogFieldsMdcHandler.getInstance().removeSupportablityComponentUUID();
95 LogFieldsMdcHandler.getInstance().removeSupportablityComponentVersion();
96 LogFieldsMdcHandler.getInstance().removeSupportablityStatusCode();
102 public List<String> getMandatoryFields() {
103 return Collections.unmodifiableList(mandatoryFields);
107 public LoggerSupportability startTimer() {