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.types.LoggerConstants;
23 public class MdcDataErrorMessage {
25 private final String targetEntity;
26 private final String targetServiceName;
27 private final String errorDescription;
28 private final String level;
29 private final String errorCode;
32 * Instantiates a new Mdc data error message.
34 * @param targetEntity the target entity
35 * @param targetServiceName the target service name
36 * @param errorCategory the error category
37 * @param errorCode the error code
38 * @param errorDescription the error description
40 public MdcDataErrorMessage(String targetEntity, String targetServiceName, String errorCategory,
41 String errorCode, String errorDescription) {
42 this.level = errorCategory;
43 this.errorCode = errorCode;
44 this.targetEntity = targetEntity;
45 this.targetServiceName = targetServiceName;
46 this.errorDescription = errorDescription;
52 * Create error message and update mdc.
54 * @param targetEntity the target entity
55 * @param targetServiceName the target service name
56 * @param level the level
57 * @param errorCode the error code
58 * @param errorDescription the error description
60 public static void createErrorMessageAndUpdateMdc(String targetEntity, String targetServiceName,
61 String level, String errorCode,
62 String errorDescription) {
63 // don't remove this line although it seems useless
64 new MdcDataErrorMessage(targetEntity, targetServiceName, level, errorCode, errorDescription);
67 public void setMdcValues() {
68 MDC.put(LoggerConstants.ERROR_CATEGORY, this.level);
69 MDC.put(LoggerConstants.ERROR_CODE, this.errorCode);
70 MDC.put(LoggerConstants.TARGET_ENTITY, this.targetEntity);
71 MDC.put(LoggerConstants.TARGET_SERVICE_NAME, this.targetServiceName);
72 MDC.put(LoggerConstants.ERROR_DESCRIPTION, this.errorDescription);