81a22adb07d0ece39d7a4dcfe1ad0bdb89c42de1
[sdc.git] /
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;
22
23 import org.openecomp.sdc.logging.types.LoggerConstants;
24 import org.slf4j.MDC;
25
26
27 public class MdcUtil {
28
29   /**
30    * Sets values for mdc.
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 static void setValuesForMdc(String targetEntity, String targetServiceName,
39                                      String errorCategory, String errorCode,
40                                      String errorDescription) {
41     MDC.put(LoggerConstants.TARGET_ENTITY, targetEntity);
42     MDC.put(LoggerConstants.TARGET_SERVICE_NAME, targetServiceName);
43     MDC.put(LoggerConstants.ERROR_CATEGORY, errorCategory);
44     MDC.put(LoggerConstants.ERROR_CODE, errorCode);
45     MDC.put(LoggerConstants.ERROR_DESCRIPTION, errorDescription);
46   }
47
48
49   /**
50    * Init mdc.
51    *  @param serviceName the service name
52    *
53    */
54   public static void initMdc(String serviceName) {
55     MDC.put(LoggerConstants.SERVICE_NAME, serviceName);
56   }
57 }