|
@ -0,0 +1,37 @@
|
|
|
package com.yihu.base;
|
|
|
|
|
|
import ch.qos.logback.core.rolling.RollingFileAppender;
|
|
|
import ch.qos.logback.core.rolling.TriggeringPolicy;
|
|
|
import com.yihu.base.activemq.ActiveMQHelper;
|
|
|
import com.yihu.base.es.config.ElasticFactory;
|
|
|
import com.yihu.base.es.config.ElastricSearchHelper;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.event.LoggingEvent;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
public class Log2ElasticsearchAppender<E> extends RollingFileAppender{
|
|
|
|
|
|
@Autowired
|
|
|
private Log2ElasticsearchUtils log2ElasticsearchUtils;
|
|
|
|
|
|
@Autowired
|
|
|
private ActiveMQHelper activeMQHelper;
|
|
|
|
|
|
@Value("${log2es.activemq.queueName}")
|
|
|
private String queueName;
|
|
|
|
|
|
public Log2ElasticsearchAppender() {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void append(Object event) {
|
|
|
if(log2ElasticsearchUtils.checkEsConnection()){
|
|
|
LoggingEvent loggingEvent = (LoggingEvent)event;
|
|
|
activeMQHelper.send(queueName,loggingEvent.getMessage());
|
|
|
return;
|
|
|
}
|
|
|
super.subAppend(event);
|
|
|
}
|
|
|
|
|
|
}
|