tuonina 6 жил өмнө
parent
commit
5e5df5fddc

+ 50 - 0
zen-core/src/main/java/cn/gygxzc/envir/core/logger/MQAppender.java

@@ -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);
+        }
+    }
+}

+ 1 - 1
zen-web/src/main/resources/logback-spring.xml

@@ -126,7 +126,7 @@
         </filter>
     </appender>
 
-    <appender name="MQ" class="cn.gygxzc.envir.core.log.MQAppender">
+    <appender name="MQ" class="cn.gygxzc.envir.core.logger.MQAppender">
         <sysName>${appName}</sysName>
     </appender>
     <!--实现分布式收集日志的appender-->