2 * Copyright 2017 ZTE Corporation.
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.
16 package org.openo.log.api;
18 import java.io.Serializable;
19 import java.util.HashMap;
21 import java.util.Map.Entry;
22 import org.slf4j.Logger;
24 import org.openo.log.impl.Facitility;
25 import org.slf4j.LoggerFactory;
30 * @author Huabing Zhao
34 public class LogMessage implements Serializable {
35 private static final Logger LOGGER = LoggerFactory.getLogger(LogMessage.class.getName());
37 protected long id = -1;
40 protected String detail = null;
42 protected String hostname = "";
46 private String logType = "";
49 protected HashMap<String, Object> extendedFields = null;
51 private HashMap<String, String> localeMap = null;
55 private static final long serialVersionUID = 200408041651009L;
57 public String getDetail() {
66 public String getHostname() {
72 public LogMessage() {}
76 public String getLogType() {
80 public void setLogType(String logType) {
81 this.logType = logType;
84 public HashMap<String, Object> getExtendedFields() {
85 return extendedFields;
88 public void setExtendedFields(HashMap<String, Object> extendedFields) {
89 this.extendedFields = extendedFields;
92 public HashMap<String, String> getLocaleMap() {
93 return this.localeMap;
96 public void setLocalMap(HashMap<String, String> localeMap) {
97 this.localeMap = localeMap;
100 protected void set(String condName, Object condValue) {
101 if (condValue != null && !"".equals(condValue)) {
102 if (localeMap == null) {
103 localeMap = new HashMap<String, String>();
105 localeMap.put(condName, condValue.toString());
111 protected void setLocale(String condName, String condValue) {
113 if (condValue != null && !"".equals(condValue)) {
114 if (localeMap == null) {
115 localeMap = new HashMap<String, String>();
120 Map<String, String> mapJson = Facitility.readJson2Map(condValue);
121 for (Entry<String, String> entry : mapJson.entrySet()) {
122 String key = entry.getKey();
124 String value = entry.getValue().replace("\"", "\'");
125 localeMap.put(condName + "_" + key, value);