init code
[vfc/nfvo/wfengine.git] / wso2 / logging-sdk / src / main / java / org / openo / log / api / LogMessage.java
1 /**
2  * Copyright 2017 ZTE Corporation.
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 package org.openo.log.api;
17
18 import java.io.Serializable;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Map.Entry;
22 import org.slf4j.Logger;
23
24 import org.openo.log.impl.Facitility;
25 import org.slf4j.LoggerFactory;
26
27
28 /**
29  * 
30  * @author Huabing Zhao
31  *
32  */
33
34 public class LogMessage implements Serializable {
35   private static final Logger LOGGER = LoggerFactory.getLogger(LogMessage.class.getName());
36
37   protected long id = -1;
38
39
40   protected String detail = null;
41
42   protected String hostname = "";
43
44
45
46   private String logType = "";
47
48
49   protected HashMap<String, Object> extendedFields = null;
50
51   private HashMap<String, String> localeMap = null;
52
53
54
55   private static final long serialVersionUID = 200408041651009L;
56
57   public String getDetail() {
58     return detail;
59   }
60
61
62   public long getId() {
63     return id;
64   }
65
66   public String getHostname() {
67     return hostname;
68   }
69
70
71
72   public LogMessage() {}
73
74
75
76   public String getLogType() {
77     return logType;
78   }
79
80   public void setLogType(String logType) {
81     this.logType = logType;
82   }
83
84   public HashMap<String, Object> getExtendedFields() {
85     return extendedFields;
86   }
87
88   public void setExtendedFields(HashMap<String, Object> extendedFields) {
89     this.extendedFields = extendedFields;
90   }
91
92   public HashMap<String, String> getLocaleMap() {
93     return this.localeMap;
94   }
95
96   public void setLocalMap(HashMap<String, String> localeMap) {
97     this.localeMap = localeMap;
98   }
99
100   protected void set(String condName, Object condValue) {
101     if (condValue != null && !"".equals(condValue)) {
102       if (localeMap == null) {
103         localeMap = new HashMap<String, String>();
104       }
105       localeMap.put(condName, condValue.toString());
106
107     }
108   }
109
110
111   protected void setLocale(String condName, String condValue) {
112
113     if (condValue != null && !"".equals(condValue)) {
114       if (localeMap == null) {
115         localeMap = new HashMap<String, String>();
116       }
117
118
119
120       Map<String, String> mapJson = Facitility.readJson2Map(condValue);
121       for (Entry<String, String> entry : mapJson.entrySet()) {
122         String key = entry.getKey();
123
124         String value = entry.getValue().replace("\"", "\'");
125         localeMap.put(condName + "_" + key, value);
126       }
127     }
128
129   }
130
131
132 }