Commit 069afb2a by Dave Syer

Use logback by default in Eureka server

Now that blitz4j 1.36.0 is out, with a bit of hackery we can prevent it from barfing on startup. Seems worth it (and certainly makes it easier to embed Eureka server). Fixes gh-3
parent be0c2287
......@@ -151,6 +151,10 @@
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
<exclusion>
<artifactId>com.netflix.blitz4j</artifactId>
<groupId>blitz4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Eureka core dep that is now optional -->
......@@ -163,7 +167,7 @@
<dependency>
<groupId>com.netflix.blitz4j</groupId>
<artifactId>blitz4j</artifactId>
<version>1.34</version>
<version>1.36.0</version>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
......
......@@ -20,16 +20,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -38,12 +28,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
......@@ -58,6 +42,10 @@
<artifactId>eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.blitz4j</groupId>
<artifactId>blitz4j</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
</dependency>
......@@ -69,6 +57,16 @@
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-core</artifactId>
<exclusions>
<exclusion>
<artifactId>blitz4j</artifactId>
<groupId>com.netflix.blitz4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.netflix.archaius</groupId>
<artifactId>archaius-core</artifactId>
</dependency>
<!-- Eureka deps that are now optional in eureka -->
<dependency>
......@@ -76,10 +74,6 @@
<artifactId>xstream</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.blitz4j</groupId>
<artifactId>blitz4j</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- Only needed at compile time -->
......
......@@ -20,7 +20,9 @@ import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
......@@ -33,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.logging.log4j.Log4JLoggingSystem;
import org.springframework.cloud.netflix.eureka.DataCenterAwareMarshallingStrategy;
import org.springframework.cloud.netflix.eureka.DiscoveryManagerInitializer;
......@@ -49,9 +52,12 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.context.ServletContextAware;
import com.netflix.blitz4j.DefaultBlitz4jConfig;
import com.netflix.blitz4j.LoggingConfiguration;
import com.netflix.discovery.converters.JsonXStream;
import com.netflix.discovery.converters.XmlXStream;
......@@ -89,6 +95,36 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
this.servletContext = servletContext;
}
@PostConstruct
public void initLogging() {
if (!(LoggingSystem.get(ClassUtils.getDefaultClassLoader()) instanceof Log4JLoggingSystem)) {
LoggingConfiguration off = new LoggingConfiguration() {
@Override
public void configure() {
}
};
Field instance = ReflectionUtils.findField(LoggingConfiguration.class,
"instance");
ReflectionUtils.makeAccessible(instance);
ReflectionUtils.setField(instance, null, off);
Field blitz4j = ReflectionUtils.findField(LoggingConfiguration.class,
"blitz4jConfig");
ReflectionUtils.makeAccessible(blitz4j);
try {
Properties props = PropertiesLoaderUtils
.loadAllProperties(new ClassPathResource("log4j.properties",
Log4JLoggingSystem.class).toString());
DefaultBlitz4jConfig blit4jConfig = new DefaultBlitz4jConfig(props);
ReflectionUtils.setField(blitz4j, off, blit4jConfig);
}
catch (IOException e) {
}
}
}
@Bean
@ConditionalOnMissingBean(DiscoveryManagerInitializer.class)
public DiscoveryManagerInitializer discoveryManagerIntitializer() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment