|
@@ -3,8 +3,6 @@ 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;
|
|
|
|
|
@@ -16,8 +14,10 @@ import org.slf4j.LoggerFactory;
|
|
|
public class MQAppender extends AppenderBase<ILoggingEvent> {
|
|
|
private final static Logger logger = LoggerFactory.getLogger(MQAppender.class);
|
|
|
|
|
|
- private IMessagerSender mMessageSender;
|
|
|
+ private ILoggerSender mMessageSender;
|
|
|
private String sysName;
|
|
|
+ private int maxRetryCount = 5;
|
|
|
+ private int currentCount = 0;
|
|
|
|
|
|
public MQAppender() {
|
|
|
logger.debug("construct");
|
|
@@ -32,19 +32,27 @@ public class MQAppender extends AppenderBase<ILoggingEvent> {
|
|
|
}
|
|
|
|
|
|
private void ensureSender() {
|
|
|
- if (mMessageSender == null) {
|
|
|
- mMessageSender = ApplicationUtils.getBean(IMessagerSender.class);
|
|
|
+ if (mMessageSender == null && currentCount < maxRetryCount) {
|
|
|
+ mMessageSender = ApplicationUtils.getBean(ILoggerSender.class);
|
|
|
+ currentCount++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
protected void append(ILoggingEvent eventObject) {
|
|
|
- LogMessage message = new LogMessage(eventObject,sysName);
|
|
|
+ LogMessage message = new LogMessage(eventObject, sysName);
|
|
|
ensureSender();
|
|
|
if (mMessageSender != null) {
|
|
|
mMessageSender.send(message);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void setMaxRetryCount(int maxRetryCount) {
|
|
|
+ this.maxRetryCount = maxRetryCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getMaxRetryCount() {
|
|
|
+ return maxRetryCount;
|
|
|
+ }
|
|
|
}
|