2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.logging.context.impl;
23 import org.openecomp.sdc.logging.api.Logger;
24 import org.openecomp.sdc.logging.api.LoggerFactory;
25 import org.openecomp.sdc.logging.context.MdcData;
26 import org.openecomp.sdc.logging.messages.DebugMessages;
27 import org.openecomp.sdc.logging.types.DebugConstants;
28 import org.openecomp.sdc.logging.types.LoggerErrorCategory;
29 import org.openecomp.sdc.logging.util.LoggingUtils;
31 import java.util.HashMap;
34 public class MdcDataDebugMessage extends MdcData {
36 private static Logger logger;
37 private static Map<String, String> mapExitOrEntryToMessage;
40 mapExitOrEntryToMessage = new HashMap<>();
41 mapExitOrEntryToMessage.put(DebugConstants.ENTER, DebugMessages.ENTER_METHOD);
42 mapExitOrEntryToMessage.put(DebugConstants.ENTER_DEFAULT, DebugMessages.DEFAULT_ENTER_METHOD);
43 mapExitOrEntryToMessage.put(DebugConstants.EXIT, DebugMessages.EXIT_METHOD);
44 mapExitOrEntryToMessage.put(DebugConstants.EXIT_DEFAULT, DebugMessages.DEFAULT_EXIT_METHOD);
47 public MdcDataDebugMessage() {
48 super(LoggerErrorCategory.DEBUG.name(), null);
51 //todo add more explanations as to the first parameter structure in case of multiples and in
52 // case of no params in method
54 * Debug entry message.
56 * @param entityParameter the entity parameter
59 public void debugEntryMessage(String entityParameter, String... ids) {
60 logDebugMessage(entityParameter, DebugConstants.ENTER, ids);
66 * @param entityParameter the entity parameter
69 public void debugExitMessage(String entityParameter, String... ids) {
70 logDebugMessage(entityParameter, DebugConstants.EXIT, ids);
73 public void logDebugMessage(String entityParameter, String enterOrExit, String... ids) {
74 String methodName = LoggingUtils.getCallingMethodNameForDebugging();
75 String declaringClass = LoggingUtils.getDeclaringClass();
76 logger = (Logger) LoggerFactory.getLogger(declaringClass);
77 String messageToWrite;
79 if (entityParameter == null || ids == null) {
80 messageToWrite = mapExitOrEntryToMessage.get(enterOrExit + "_" + DebugConstants.DEFAULT);
81 logger.debug(String.format(messageToWrite, methodName));
83 messageToWrite = mapExitOrEntryToMessage.get(enterOrExit);
85 .format(messageToWrite, methodName, entityParameter, String.join(",", ids)));