[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-logging-lib / openecomp-sdc-logging-core / src / main / java / org / openecomp / sdc / logging / context / impl / MdcDataErrorMessage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  */
20
21 package org.openecomp.sdc.logging.context.impl;
22
23 import org.openecomp.sdc.logging.context.MdcData;
24 import org.openecomp.sdc.logging.types.LoggerConstants;
25 import org.slf4j.MDC;
26
27
28 public class MdcDataErrorMessage extends MdcData {
29   private String targetEntity;
30   private String targetServiceName;
31   private String errorDescription;
32
33   /**
34    * Instantiates a new Mdc data error message.
35    *
36    * @param targetEntity      the target entity
37    * @param targetServiceName the target service name
38    * @param errorCategory     the error category
39    * @param errorCode         the error code
40    * @param errorDescription  the error description
41    */
42   public MdcDataErrorMessage(String targetEntity, String targetServiceName, String errorCategory,
43                              String errorCode, String errorDescription) {
44     super(errorCategory, errorCode);
45     this.targetEntity = targetEntity;
46     this.targetServiceName = targetServiceName;
47     this.errorDescription = errorDescription;
48
49     this.setMdcValues();
50   }
51
52   /**
53    * Create error message and update mdc.
54    *
55    * @param targetEntity      the target entity
56    * @param targetServiceName the target service name
57    * @param level             the level
58    * @param errorCode         the error code
59    * @param errorDescription  the error description
60    */
61   public static void createErrorMessageAndUpdateMdc(String targetEntity, String targetServiceName,
62                                                     String level, String errorCode,
63                                                     String errorDescription) {
64     MdcDataErrorMessage mdcDataErrorMessage =
65         new MdcDataErrorMessage(targetEntity, targetServiceName, level, errorCode,
66             errorDescription);
67   }
68
69   @Override
70   public void setMdcValues() {
71     super.setMdcValues();
72     MDC.put(LoggerConstants.TARGET_ENTITY, this.targetEntity);
73     MDC.put(LoggerConstants.TARGET_SERVICE_NAME, this.targetServiceName);
74     MDC.put(LoggerConstants.ERROR_DESCRIPTION, this.errorDescription);
75   }
76 }