2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.logging.context.impl;
19 import org.openecomp.sdc.logging.api.Logger;
20 import org.openecomp.sdc.logging.api.LoggerFactory;
21 import org.openecomp.sdc.logging.context.MdcData;
22 import org.openecomp.sdc.logging.messages.DebugMessages;
23 import org.openecomp.sdc.logging.types.DebugConstants;
24 import org.openecomp.sdc.logging.types.LoggerErrorCategory;
25 import org.openecomp.sdc.logging.util.LoggingUtils;
27 import java.util.HashMap;
30 public class MdcDataDebugMessage extends MdcData {
32 private Logger logger;
33 private static Map<String, String> mapExitOrEntryToMessage;
36 mapExitOrEntryToMessage = new HashMap<>();
37 mapExitOrEntryToMessage.put(DebugConstants.ENTER, DebugMessages.ENTER_METHOD);
38 mapExitOrEntryToMessage.put(DebugConstants.ENTER_DEFAULT, DebugMessages.DEFAULT_ENTER_METHOD);
39 mapExitOrEntryToMessage.put(DebugConstants.EXIT, DebugMessages.EXIT_METHOD);
40 mapExitOrEntryToMessage.put(DebugConstants.EXIT_DEFAULT, DebugMessages.DEFAULT_EXIT_METHOD);
43 public MdcDataDebugMessage() {
44 super(LoggerErrorCategory.DEBUG.name(), null);
47 //todo add more explanations as to the first parameter structure in case of multiples and in
48 // case of no params in method
50 * Debug entry message.
52 * @param entityParameter the entity parameter
55 public void debugEntryMessage(String entityParameter, String... ids) {
56 logDebugMessage(entityParameter, DebugConstants.ENTER, ids);
62 * @param entityParameter the entity parameter
65 public void debugExitMessage(String entityParameter, String... ids) {
66 logDebugMessage(entityParameter, DebugConstants.EXIT, ids);
69 private void logDebugMessage(String entityParameter, String enterOrExit, String... ids) {
70 String methodName = LoggingUtils.getCallingMethodNameForDebugging();
71 String declaringClass = LoggingUtils.getDeclaringClass();
72 logger = LoggerFactory.getLogger(declaringClass);
73 String messageToWrite;
75 if (entityParameter == null || ids == null) {
76 messageToWrite = mapExitOrEntryToMessage.get(enterOrExit + "_" + DebugConstants.DEFAULT);
77 logger.debug(String.format(messageToWrite, methodName));
79 messageToWrite = mapExitOrEntryToMessage.get(enterOrExit);
81 .format(messageToWrite, methodName, entityParameter, String.join(",", ids)));