<dependencies>
<dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- <version>1.9.9</version>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.7.3</version>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.10</version>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.7.3</version>
</dependency>
+
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.5.1</version>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>1.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-access</artifactId>
+ <version>1.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>net.logstash.logback</groupId>
+ <artifactId>logstash-logback-encoder</artifactId>
+ <version>4.8</version>
</dependency>
</dependencies>
<build>
public long recordSecLog(SecLogMessage logMessage) {
// TODO Auto-generated method stub
- LOGGER.info("receive a insert sec log message");
+ //LOGGER.info("receive a insert sec log message");
InsertLogHandler insertLogHandler = new InsertLogHandler();
if (insertLogHandler.checkSecLog((SecLogMessage) logMessage)) {
public long recordSysLog(SysLogMessage logMessage) {
- LOGGER.info("receive a insert sys log message");
+ //LOGGER.info("receive a insert sys log message");
InsertLogHandler insertLogHandler = new InsertLogHandler();
if (insertLogHandler.checkSysLog((SysLogMessage) logMessage)) {
this.setLogType(LogConst.SYSLOG_TYPE);
this.logName = logName;
- this.setLocale("logName", logName);
+ this.set("logName", logName);
this.rank = rank;
this.set("rank", rank);
this.set("hostname", hostname);
this.detail = detail;
- this.setLocale("detail", detail);
+ this.set("detail", detail);
this.logStartDate = logStartDate;
this.set("logStartDate", Facitility.dateFormat(logStartDate));
import java.util.Map;
import java.util.Map.Entry;
-import org.codehaus.jackson.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Facitility {
json = w.toString();
w.close();
} catch (IOException e) {
- LOGGER.error("IOException" + e);
+ LOGGER.error("IOException", e);
}
return json;
}
Map<String, String> maps = objectMapper.readValue(json, Map.class);
return maps;
} catch (Exception e) {
- LOGGER.error("IOException" + e);
+ LOGGER.error("IOException", e);
return null;
}
}
}
public static String checkRequiredJsonParam(String jsonParam, String key) {
- StringBuilder errMsg = new StringBuilder();
- try {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode jsonValue;
-
-
- jsonValue = mapper.readTree(jsonParam.toString());
- Iterator<Entry<String, JsonNode>> elements = jsonValue.fields();
- while (elements.hasNext()) {
- Entry<String, JsonNode> node = elements.next();
- String childValue = node.getValue().asText();
- if (childValue == null || "".equals(childValue)) {
- errMsg.append(
- "Both Chinese and English descriptions of this field cannot be empty: " + key + "/n");
- break;
- }
- }
-
- return errMsg.toString();
- } catch (JsonProcessingException e) {
- // TODO Auto-generated catch block
- LOGGER.error("JsonProcessingException" + e);
- return errMsg.toString();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- LOGGER.error("IOException" + e);
- return errMsg.toString();
- }
+ return "";
+// StringBuilder errMsg = new StringBuilder();
+// try {
+// ObjectMapper mapper = new ObjectMapper();
+// JsonNode jsonValue;
+//
+//
+// jsonValue = mapper.readTree(jsonParam.toString());
+// Iterator<Entry<String, JsonNode>> elements = jsonValue.fields();
+// while (elements.hasNext()) {
+// Entry<String, JsonNode> node = elements.next();
+// String childValue = node.getValue().asText();
+// if (childValue == null || "".equals(childValue)) {
+// errMsg.append(
+// "Both Chinese and English descriptions of this field cannot be empty: " + key + "/n");
+// break;
+// }
+// }
+//
+// return errMsg.toString();
+// } catch (JsonProcessingException e) {
+// // TODO Auto-generated catch block
+// LOGGER.error("JsonProcessingException" , e);
+// return errMsg.toString();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// LOGGER.error("IOException" , e);
+// return errMsg.toString();
+// }
}
}
--- /dev/null
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.log.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+
+import org.openo.log.api.LogService;
+import org.openo.log.api.SysLogMessage;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+
+/**
+ * @author Huabing Zhao
+ *
+ */
+public class TestLogback2Logstash {
+
+ /**
+ * @param args
+ * @throws JoranException
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public static void main(String[] args) throws JoranException, IOException, InterruptedException {
+ LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
+ loggerContext.reset();
+ JoranConfigurator configurator = new JoranConfigurator();
+ InputStream configStream = TestLogback2Logstash.class.getResourceAsStream("logback.xml");
+ configurator.setContext(loggerContext);
+ configurator.doConfigure(configStream); // loads logback file
+ configStream.close();
+
+ for (int i = 0; i < 10; i++) {
+ SysLogMessage sysLogMessage = new SysLogMessage("a sys log example", "www.open-o.org",
+ LogService.SYSLOG_RANK_WARN, "logdetails", new Date(), new Date());
+ LogService.getInstance().recordSysLog(sysLogMessage);
+ }
+ loggerContext.stop();
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
+ <destination>127.0.0.1:4560</destination>
+
+ <!-- encoder is required -->
+ <encoder class="net.logstash.logback.encoder.LogstashEncoder" />
+ </appender>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>
+ %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
+ </Pattern>
+ </layout>
+ </appender>
+
+ <root level="debug">
+ <appender-ref ref="stash" />
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration>
\ No newline at end of file