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