|
@@ -0,0 +1,50 @@
|
|
|
+package cn.gygxzc.envir.core.logger;
|
|
|
+
|
|
|
+import ch.qos.logback.classic.spi.ILoggingEvent;
|
|
|
+import ch.qos.logback.core.AppenderBase;
|
|
|
+import cn.gygxzc.envir.core.utils.ApplicationUtils;
|
|
|
+import cn.gygxzc.tina.cloud.bus.message.LogMessage;
|
|
|
+import cn.gygxzc.tina.cloud.bus.messager.sender.IMessagerSender;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by niantuo on 2018/11/5.
|
|
|
+ * 这个异步日志收集。
|
|
|
+ * 利用Rabbitmq 消息中间件,将日志异步传递的日志分析系统中统计去记录和处理
|
|
|
+ */
|
|
|
+public class MQAppender extends AppenderBase<ILoggingEvent> {
|
|
|
+ private final static Logger logger = LoggerFactory.getLogger(MQAppender.class);
|
|
|
+
|
|
|
+ private IMessagerSender mMessageSender;
|
|
|
+ private String sysName;
|
|
|
+
|
|
|
+ public MQAppender() {
|
|
|
+ logger.debug("construct");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSysName(String sysName) {
|
|
|
+ this.sysName = sysName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getSysName() {
|
|
|
+ return sysName;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ensureSender() {
|
|
|
+ if (mMessageSender == null) {
|
|
|
+ mMessageSender = ApplicationUtils.getBean(IMessagerSender.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void append(ILoggingEvent eventObject) {
|
|
|
+ LogMessage message = new LogMessage(eventObject,sysName);
|
|
|
+ ensureSender();
|
|
|
+ if (mMessageSender != null) {
|
|
|
+ mMessageSender.send(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|