1 package org.openecomp.sdc.common.log.elements;
3 import org.openecomp.sdc.common.log.api.ILogConfiguration;
4 import org.openecomp.sdc.common.log.api.ILogFieldsHandler;
5 import org.openecomp.sdc.common.log.enums.LogLevel;
6 import org.openecomp.sdc.common.log.enums.LogMarkers;
7 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
8 import org.openecomp.sdc.common.log.enums.StatusCode;
9 import org.slf4j.Logger;
10 import org.slf4j.MarkerFactory;
14 public class LoggerSupportability extends LoggerBase {
16 public LoggerSupportability(ILogFieldsHandler ecompLogFieldsHandler, Logger logger) {
17 super(ecompLogFieldsHandler, MarkerFactory.getMarker(LogMarkers.SUPPORTABILITY_MARKER.text()),
21 public static LoggerSupportability getLogger(String className) {
22 return LoggerFactory.getMdcLogger(LoggerSupportability.class,
23 org.slf4j.LoggerFactory.getLogger(className));
27 public void log(LoggerSupportabilityActions action, Map<String,String> componentMetaData,StatusCode statusCode, String message, Object...params) {
28 fillFieldsBeforeLogging(action,componentMetaData,statusCode);
29 super.log(LogLevel.INFO,message, params);
32 public void log(LoggerSupportabilityActions action, StatusCode statusCode, String message, Object...params) {
33 log(action, null, statusCode, message, params);
36 private static ArrayList<String> mandatoryFields = new ArrayList<>(Arrays.asList(
37 ILogConfiguration.MDC_SUPPORTABLITY_ACTION,
38 ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID,
39 ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION,
40 ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME,
41 ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID,
42 ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION,
43 ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE));
45 private void fillFieldsBeforeLogging(LoggerSupportabilityActions action, Map<String,String> componentMetaData,StatusCode statusCode) {
47 if (componentMetaData!=null){
48 ecompLogFieldsHandler.setSupportablityCsarUUID(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID));
49 ecompLogFieldsHandler.setSupportablityCsarVersion(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION));
50 ecompLogFieldsHandler.setSupportablityComponentName(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME));
51 ecompLogFieldsHandler.setSupportablityComponentUUID(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID));
52 ecompLogFieldsHandler.setSupportablityComponentVersion(componentMetaData.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION));
54 ecompLogFieldsHandler.setSupportablityAction(action.getName());
55 ecompLogFieldsHandler.setSupportablityStatusCode(statusCode.getStatusCodeEnum());
59 public LoggerSupportability clear(){
60 LogFieldsMdcHandler.getInstance().removeSupportablityAction();
61 LogFieldsMdcHandler.getInstance().removeSupportablityCsarUUID();
62 LogFieldsMdcHandler.getInstance().removeSupportablityCsarVersion();
63 LogFieldsMdcHandler.getInstance().removeSupportablityComponentName();
64 LogFieldsMdcHandler.getInstance().removeSupportablityComponentUUID();
65 LogFieldsMdcHandler.getInstance().removeSupportablityComponentVersion();
66 LogFieldsMdcHandler.getInstance().removeSupportablityStatusCode();
72 public List<String> getMandatoryFields() {
73 return Collections.unmodifiableList(mandatoryFields);
77 public LoggerSupportability startTimer() {