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(Class<?> clazz) {
55 return LoggerFactory.getMdcLogger(LoggerSupportability.class, org.slf4j.LoggerFactory.getLogger(clazz));
58 public static LoggerSupportability getLogger(String className) {
59 return LoggerFactory.getMdcLogger(LoggerSupportability.class,
60 org.slf4j.LoggerFactory.getLogger(className));
63 public void log(LoggerSupportabilityActions action, Map<String, String> componentMetaData, StatusCode statusCode,
64 String message, Object... params) {
65 fillFieldsBeforeLogging(action, componentMetaData, statusCode);
66 super.log(LogLevel.INFO, message, params);
69 public void log(LoggerSupportabilityActions action, StatusCode statusCode, String message, Object... params) {
70 log(action, null, statusCode, message, params);
73 private void fillFieldsBeforeLogging(LoggerSupportabilityActions action, Map<String, String> componentMetaData,
74 StatusCode statusCode) {
76 if (componentMetaData != null) {
78 .setSupportablityCsarUUID(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID));
80 .setSupportablityCsarVersion(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION));
81 ecompLogFieldsHandler.setSupportablityComponentName(
82 componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME));
83 ecompLogFieldsHandler.setSupportablityComponentUUID(
84 componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID));
85 ecompLogFieldsHandler.setSupportablityComponentVersion(
86 componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION));
88 ecompLogFieldsHandler.setSupportablityAction(action.getName());
89 ecompLogFieldsHandler.setSupportablityStatusCode(statusCode.getStatusCode());
93 public LoggerSupportability clear() {
94 LogFieldsMdcHandler.getInstance().removeSupportablityAction();
95 LogFieldsMdcHandler.getInstance().removeSupportablityCsarUUID();
96 LogFieldsMdcHandler.getInstance().removeSupportablityCsarVersion();
97 LogFieldsMdcHandler.getInstance().removeSupportablityComponentName();
98 LogFieldsMdcHandler.getInstance().removeSupportablityComponentUUID();
99 LogFieldsMdcHandler.getInstance().removeSupportablityComponentVersion();
100 LogFieldsMdcHandler.getInstance().removeSupportablityStatusCode();
106 public List<String> getMandatoryFields() {
107 return Collections.unmodifiableList(mandatoryFields);
111 public LoggerSupportability startTimer() {