|
@@ -1,15 +1,8 @@
|
|
|
package cc.mrbird.febs.common.logging.starter.configure;
|
|
package cc.mrbird.febs.common.logging.starter.configure;
|
|
|
|
|
|
|
|
import cc.mrbird.febs.common.logging.starter.properties.FebsLogProperties;
|
|
import cc.mrbird.febs.common.logging.starter.properties.FebsLogProperties;
|
|
|
-import ch.qos.logback.classic.Level;
|
|
|
|
|
import ch.qos.logback.classic.Logger;
|
|
import ch.qos.logback.classic.Logger;
|
|
|
import ch.qos.logback.classic.LoggerContext;
|
|
import ch.qos.logback.classic.LoggerContext;
|
|
|
-import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
|
|
|
|
|
-import ch.qos.logback.classic.filter.LevelFilter;
|
|
|
|
|
-import ch.qos.logback.classic.spi.ILoggingEvent;
|
|
|
|
|
-import ch.qos.logback.core.rolling.RollingFileAppender;
|
|
|
|
|
-import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
|
|
|
|
|
-import ch.qos.logback.core.spi.FilterReply;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import net.logstash.logback.appender.LogstashTcpSocketAppender;
|
|
import net.logstash.logback.appender.LogstashTcpSocketAppender;
|
|
@@ -20,12 +13,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.core.annotation.Order;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @author: xuefrye
|
|
|
|
|
|
|
+ * @author xuefrye
|
|
|
*/
|
|
*/
|
|
|
@Configuration
|
|
@Configuration
|
|
|
@EnableConfigurationProperties(FebsLogProperties.class)
|
|
@EnableConfigurationProperties(FebsLogProperties.class)
|
|
@@ -39,12 +31,12 @@ public class FebsLogAutoConfigure {
|
|
|
this.properties = properties;
|
|
this.properties = properties;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static final LoggerContext context;
|
|
|
|
|
- private static final Logger rootLogger;
|
|
|
|
|
|
|
+ private static final LoggerContext CONTEXT;
|
|
|
|
|
+ private static final Logger ROOTLOGGER;
|
|
|
|
|
|
|
|
- static{
|
|
|
|
|
- context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
|
|
|
|
- rootLogger = context.getLogger("ROOT");
|
|
|
|
|
|
|
+ static {
|
|
|
|
|
+ CONTEXT = (LoggerContext) LoggerFactory.getILoggerFactory();
|
|
|
|
|
+ ROOTLOGGER = CONTEXT.getLogger("ROOT");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@ConditionalOnProperty(name = "febs.log.enable-elk", havingValue = "true", matchIfMissing = true)
|
|
@ConditionalOnProperty(name = "febs.log.enable-elk", havingValue = "true", matchIfMissing = true)
|
|
@@ -62,7 +54,7 @@ public class FebsLogAutoConfigure {
|
|
|
appender.addDestination(properties.getLogstashHost());
|
|
appender.addDestination(properties.getLogstashHost());
|
|
|
appender.setName("logstash[" + applicationName + "]");
|
|
appender.setName("logstash[" + applicationName + "]");
|
|
|
appender.start();
|
|
appender.start();
|
|
|
- appender.setContext(context);
|
|
|
|
|
- rootLogger.addAppender(appender);
|
|
|
|
|
|
|
+ appender.setContext(CONTEXT);
|
|
|
|
|
+ ROOTLOGGER.addAppender(appender);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|