diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java index 0796c7fc2bb..385821119b1 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/DataEndpointMBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,18 +32,6 @@ import org.springframework.jmx.export.annotation.ManagedResource; @ManagedResource public class DataEndpointMBean extends EndpointMBean { - /** - * Create a new {@link DataEndpointMBean} instance. - * @param beanName the bean name - * @param endpoint the endpoint to wrap - * @deprecated since 1.3 in favor of - * {@link #DataEndpointMBean(String, Endpoint, ObjectMapper)} - */ - @Deprecated - public DataEndpointMBean(String beanName, Endpoint> endpoint) { - super(beanName, endpoint); - } - /** * Create a new {@link DataEndpointMBean} instance. * @param beanName the bean name diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java index eac0dc9816a..2a6cec2f3a6 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,18 +40,6 @@ public class EndpointMBean { private final ObjectMapper mapper; - /** - * Create a new {@link EndpointMBean} instance. - * @param beanName the bean name - * @param endpoint the endpoint to wrap - * @deprecated since 1.3 in favor of - * {@link #EndpointMBean(String, Endpoint, ObjectMapper)} - */ - @Deprecated - public EndpointMBean(String beanName, Endpoint> endpoint) { - this(beanName, endpoint, new ObjectMapper()); - } - /** * Create a new {@link EndpointMBean} instance. * @param beanName the bean name diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java index 1f5ffb1f071..1af2ec2477f 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/ShutdownEndpointMBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,18 +32,6 @@ import org.springframework.jmx.export.annotation.ManagedResource; @ManagedResource public class ShutdownEndpointMBean extends EndpointMBean { - /** - * Create a new {@link ShutdownEndpointMBean} instance. - * @param beanName the bean name - * @param endpoint the endpoint to wrap - * @deprecated since 1.3 in favor of - * {@link #ShutdownEndpointMBean(String, Endpoint, ObjectMapper)} - */ - @Deprecated - public ShutdownEndpointMBean(String beanName, Endpoint> endpoint) { - super(beanName, endpoint); - } - /** * Create a new {@link ShutdownEndpointMBean} instance. * @param beanName the bean name diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DropwizardMetricWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DropwizardMetricWriter.java deleted file mode 100644 index 6e4793b0dfb..00000000000 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DropwizardMetricWriter.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2012-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.metrics.writer; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; - -import com.codahale.metrics.Counter; -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Histogram; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.Timer; - -import org.springframework.boot.actuate.metrics.Metric; -import org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices; - -/** - * A {@link MetricWriter} that send data to a Dropwizard {@link MetricRegistry} based on a - * naming convention. - * - *
- * VCAP_APPLICATION: {"instance_id":"2ce0ac627a6c8e47e936d829a3a47b5b","instance_index":0,
- * "version":"0138c4a6-2a73-416b-aca0-572c09f7ca53","name":"foo",
- * "uris":["foo.cfapps.io"], ...}
- * VCAP_SERVICES: {"rds-mysql-1.0":[{"name":"mysql","label":"rds-mysql-1.0","plan":"10mb",
- * "credentials":{"name":"d04fb13d27d964c62b267bbba1cffb9da","hostname":"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com",
- * "host":"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com","port":3306,"user":"urpRuqTf8Cpe6",
- * "username":"urpRuqTf8Cpe6","password":"pxLsGVpsC9A5S"}
- * }]}
- *
- *
- * These objects are flattened into properties. The VCAP_APPLICATION object goes straight
- * to {@code vcap.application.*} in a fairly obvious way, and the VCAP_SERVICES object is
- * unwrapped so that it is a hash of objects with key equal to the service instance name
- * (e.g. "mysql" in the example above), and value equal to that instances properties, and
- * then flattened in the same way. E.g.
- *
- * - * vcap.application.instance_id: 2ce0ac627a6c8e47e936d829a3a47b5b - * vcap.application.version: 0138c4a6-2a73-416b-aca0-572c09f7ca53 - * vcap.application.name: foo - * vcap.application.uris[0]: foo.cfapps.io - * - * vcap.services.mysql.name: mysql - * vcap.services.mysql.label: rds-mysql-1.0 - * vcap.services.mysql.credentials.name: d04fb13d27d964c62b267bbba1cffb9da - * vcap.services.mysql.credentials.port: 3306 - * vcap.services.mysql.credentials.host: mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com - * vcap.services.mysql.credentials.username: urpRuqTf8Cpe6 - * vcap.services.mysql.credentials.password: pxLsGVpsC9A5S - * ... - *- * - * N.B. this initializer is mainly intended for informational use (the application and - * instance ids are particularly useful). For service binding you might find that Spring - * Cloud is more convenient and more robust against potential changes in Cloud Foundry. - * - * @author Dave Syer - * @author Andy Wilkinson - * @deprecated since 1.3.0 in favor of CloudFoundryVcapEnvironmentPostProcessor - */ -@Deprecated -public class VcapEnvironmentPostProcessor - extends CloudFoundryVcapEnvironmentPostProcessor { - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java index fe36e8e012f..24c8826e3f4 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -270,12 +270,6 @@ public abstract class AbstractConfigurableEmbeddedServletContainer this.registerDefaultServlet = registerDefaultServlet; } - @Override - public void setRegisterJspServlet(boolean registerJspServlet) { - Assert.notNull(this.jspServlet); - this.jspServlet.setRegistered(registerJspServlet); - } - /** * Flag to indicate that the default servlet should be registered. * @return true if the default servlet is to be registered @@ -293,12 +287,6 @@ public abstract class AbstractConfigurableEmbeddedServletContainer return this.ssl; } - @Override - public void setJspServletClassName(String jspServletClassName) { - Assert.notNull(this.jspServlet); - this.jspServlet.setClassName(jspServletClassName); - } - @Override public void setJspServlet(JspServlet jspServlet) { this.jspServlet = jspServlet; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainer.java index 94ccb039fcd..f3cfba84429 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -92,32 +92,6 @@ public interface ConfigurableEmbeddedServletContainer { */ void setAddress(InetAddress address); - /** - * The class name for the jsp servlet if used. If - * {@link #setRegisterJspServlet(boolean) registerJspServlet} is true and this - * class is on the classpath then it will be registered. Since both Tomcat and Jetty - * use Jasper for their JSP implementation the default is - * {@code org.apache.jasper.servlet.JspServlet}. - * @param jspServletClassName the class name for the JSP servlet if used - * @deprecated in 1.3.0 in favor of {@link JspServlet#setClassName(String)} - * @see #setJspServlet - * @see JspServlet#setClassName(String) - */ - @Deprecated - void setJspServletClassName(String jspServletClassName); - - /** - * Set if the JspServlet should be registered if it is on the classpath. Defaults to - * {@code true} so that files from the {@link #setDocumentRoot(File) document root} - * will be served. - * @param registerJspServlet if the JSP servlet should be registered - * @deprecated in 1.3.0 in favor of {@link JspServlet#setRegistered(boolean)} - * @see #setJspServlet - * @see JspServlet#setRegistered(boolean) - */ - @Deprecated - void setRegisterJspServlet(boolean registerJspServlet); - /** * Set if the DefaultServlet should be registered. Defaults to {@code true} so that * files from the {@link #setDocumentRoot(File) document root} will be served. diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java index 1ae19518dd7..bb63ed17499 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,8 +45,6 @@ public abstract class LoggingSystem { "org.springframework.boot.logging.logback.LogbackLoggingSystem"); systems.put("org.apache.logging.log4j.core.impl.Log4jContextFactory", "org.springframework.boot.logging.log4j2.Log4J2LoggingSystem"); - systems.put("org.apache.log4j.PropertyConfigurator", - "org.springframework.boot.logging.log4j.Log4JLoggingSystem"); systems.put("java.util.logging.LogManager", "org.springframework.boot.logging.java.JavaLoggingSystem"); SYSTEMS = Collections.unmodifiableMap(systems); @@ -69,20 +67,6 @@ public abstract class LoggingSystem { */ public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) { - initialize(configLocation, logFile); - } - - /** - * Fully initialize the logging system. - * @param configLocation a log configuration location or {@code null} if default - * initialization is required - * @param logFile the log output file that should be written or {@code null} for - * console only output - * @deprecated since 1.3 in favor of - * {@link #initialize(LoggingInitializationContext, String, LogFile)} - */ - @Deprecated - public void initialize(String configLocation, LogFile logFile) { } /** @@ -110,8 +94,7 @@ public abstract class LoggingSystem { public abstract void setLogLevel(String loggerName, LogLevel level); /** - * Detect and return the logging system in use. Supports Logback, Log4J, Log4J2 and - * Java Logging. + * Detect and return the logging system in use. Supports Logback and Java Logging. * @param classLoader the classloader * @return The logging system */ diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/log4j/Log4JLoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/log4j/Log4JLoggingSystem.java deleted file mode 100644 index cb6e954c91d..00000000000 --- a/spring-boot/src/main/java/org/springframework/boot/logging/log4j/Log4JLoggingSystem.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2012-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.logging.log4j; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; - -import org.springframework.boot.logging.LogFile; -import org.springframework.boot.logging.LogLevel; -import org.springframework.boot.logging.LoggingInitializationContext; -import org.springframework.boot.logging.LoggingSystem; -import org.springframework.boot.logging.Slf4JLoggingSystem; -import org.springframework.util.Assert; -import org.springframework.util.Log4jConfigurer; -import org.springframework.util.StringUtils; - -/** - * {@link LoggingSystem} for Log4j. - * - * @author Phillip Webb - * @author Dave Syer - * @author Andy Wilkinson - * @deprecated in Spring Boot 1.3 in favor of Apache Log4j 2 (following Apache's EOL - * declaration for log4j 1.x) - */ -@Deprecated -public class Log4JLoggingSystem extends Slf4JLoggingSystem { - - private static final Map
- * If the {@link EmbeddedWebApplicationContext} has a - * {@link EmbeddedWebApplicationContext#setNamespace(String) namespace} set, it will be - * used to construct the property name. For example, the "management" actuator context - * will have the property name {@literal "local.management.port"}. - *
- * Properties are automatically propagated up to any parent context. - * - * @author Dave Syer - * @author Phillip Webb - * @deprecated since 1.3 in favor of - * org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer - */ -@Deprecated -public class ServerPortInfoApplicationContextInitializer extends - org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer { - -} diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j/log4j-file.properties b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j/log4j-file.properties deleted file mode 100644 index 5242f3d128f..00000000000 --- a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j/log4j-file.properties +++ /dev/null @@ -1,32 +0,0 @@ -log4j.rootCategory=INFO, CONSOLE, FILE - -PID=???? -LOG_PATH=${java.io.tmpdir} -LOG_FILE=${LOG_PATH}/spring.log -LOG_LEVEL_PATTERN=%5p -LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${PID} ${LOG_LEVEL_PATTERN} [%t] --- %c{1}: %m%n - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN} - -log4j.appender.FILE=org.apache.log4j.RollingFileAppender -log4j.appender.FILE.File=${LOG_FILE} -log4j.appender.FILE.MaxFileSize=10MB -log4j.appender.FILE.layout = org.apache.log4j.PatternLayout -log4j.appender.FILE.layout.ConversionPattern=${LOG_PATTERN} - -log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR -log4j.category.org.apache.catalina.util.LifecycleBase=ERROR -log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN -log4j.category.org.apache.sshd.common.util.SecurityUtils -log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN -log4j.category.org.crsh.plugin=WARN -log4j.category.org.crsh.ssh=WARN -log4j.category.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR -log4j.category.org.hibernate.validator.internal.util.Version=WARN -log4j.category.org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration=WARN -log4j.category.org.springframework.boot.actuate.endpoint.jmx=WARN -log4j.category.org.thymeleaf=WARN - diff --git a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j/log4j.properties b/spring-boot/src/main/resources/org/springframework/boot/logging/log4j/log4j.properties deleted file mode 100644 index a8769ee7a90..00000000000 --- a/spring-boot/src/main/resources/org/springframework/boot/logging/log4j/log4j.properties +++ /dev/null @@ -1,23 +0,0 @@ -log4j.rootCategory=INFO, CONSOLE - -PID=???? -LOG_LEVEL_PATTERN=%5p -LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${PID} ${LOG_LEVEL_PATTERN} [%t] --- %c{1}: %m%n - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN} - -log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR -log4j.category.org.apache.catalina.util.LifecycleBase=ERROR -log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN -log4j.category.org.apache.sshd.common.util.SecurityUtils -log4j.category.org.apache.tomcat.util.net.NioSelectorPool=WARN -log4j.category.org.crsh.plugin=WARN -log4j.category.org.crsh.ssh=WARN -log4j.category.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR -log4j.category.org.hibernate.validator.internal.util.Version=WARN -log4j.category.org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration=WARN -log4j.category.org.springframework.boot.actuate.endpoint.jmx=WARN -log4j.category.org.thymeleaf=WARN diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index dec42064e9c..b65cd6ce2bf 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -177,24 +177,6 @@ public class SpringApplicationTests { verify(application, never()).printBanner((Environment) anyObject()); } - @SuppressWarnings("deprecation") - @Test - public void disableBannerWithBoolean() throws Exception { - SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); - application.setWebEnvironment(false); - application.setShowBanner(false); - this.context = application.run(); - verify(application, never()).printBanner((Environment) anyObject()); - } - - @Test - public void disableBannerViaShowBannerProperty() throws Exception { - SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); - application.setWebEnvironment(false); - this.context = application.run("--spring.main.show_banner=false"); - verify(application, never()).printBanner((Environment) anyObject()); - } - @Test public void disableBannerViaBannerModeProperty() throws Exception { SpringApplication application = spy(new SpringApplication(ExampleConfig.class)); diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index eabd5480e90..51ec9ceb85b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -499,11 +499,6 @@ public class LoggingApplicationListenerTests { } - @Override - public void initialize(String configLocation, LogFile logFile) { - - } - @Override public void setLogLevel(String loggerName, LogLevel level) { diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/log4j/Log4JLoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/log4j/Log4JLoggingSystemTests.java deleted file mode 100644 index 3fe02c46124..00000000000 --- a/spring-boot/src/test/java/org/springframework/boot/logging/log4j/Log4JLoggingSystemTests.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2012-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.logging.log4j; - -import java.io.File; -import java.util.logging.Handler; -import java.util.logging.LogManager; - -import org.apache.commons.logging.impl.Log4JLogger; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.slf4j.bridge.SLF4JBridgeHandler; - -import org.springframework.boot.logging.AbstractLoggingSystemTests; -import org.springframework.boot.logging.LogLevel; -import org.springframework.boot.test.OutputCapture; -import org.springframework.util.StringUtils; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -/** - * Tests for {@link Log4JLoggingSystem}. - * - * @author Phillip Webb - * @author Andy Wilkinson - */ -@SuppressWarnings("deprecation") -public class Log4JLoggingSystemTests extends AbstractLoggingSystemTests { - - @Rule - public OutputCapture output = new OutputCapture(); - - private final Log4JLoggingSystem loggingSystem = new Log4JLoggingSystem( - getClass().getClassLoader()); - - private Log4JLogger logger; - - @Before - public void setup() { - this.logger = new Log4JLogger(getClass().getName()); - } - - @Override - @After - public void clear() { - this.loggingSystem.cleanUp(); - } - - @Test - public void noFile() throws Exception { - this.loggingSystem.beforeInitialize(); - this.logger.info("Hidden"); - this.loggingSystem.initialize(null, null, null); - this.logger.info("Hello world"); - String output = this.output.toString().trim(); - assertTrue("Wrong output:\n" + output, output.contains("Hello world")); - assertFalse("Output not hidden:\n" + output, output.contains("Hidden")); - assertFalse(new File(tmpDir() + "/spring.log").exists()); - } - - @Test - public void withFile() throws Exception { - this.loggingSystem.beforeInitialize(); - this.logger.info("Hidden"); - this.loggingSystem.initialize(null, null, getLogFile(null, tmpDir())); - this.logger.info("Hello world"); - String output = this.output.toString().trim(); - assertTrue("Wrong output:\n" + output, output.contains("Hello world")); - assertFalse("Output not hidden:\n" + output, output.contains("Hidden")); - assertTrue(new File(tmpDir() + "/spring.log").exists()); - } - - @Test - public void testNonDefaultConfigLocation() throws Exception { - this.loggingSystem.beforeInitialize(); - this.loggingSystem.initialize(null, "classpath:log4j-nondefault.properties", - getLogFile(null, tmpDir())); - this.logger.info("Hello world"); - String output = this.output.toString().trim(); - assertTrue("Wrong output:\n" + output, output.contains("Hello world")); - assertTrue("Wrong output:\n" + output, output.contains(tmpDir() + "/spring.log")); - assertFalse(new File(tmpDir() + "/tmp.log").exists()); - } - - @Test(expected = IllegalStateException.class) - public void testNonexistentConfigLocation() throws Exception { - this.loggingSystem.beforeInitialize(); - this.loggingSystem.initialize(null, "classpath:log4j-nonexistent.xml", null); - } - - @Test - public void setLevel() throws Exception { - this.loggingSystem.beforeInitialize(); - this.loggingSystem.initialize(null, null, null); - this.logger.debug("Hello"); - this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG); - this.logger.debug("Hello"); - assertThat(StringUtils.countOccurrencesOf(this.output.toString(), "Hello"), - equalTo(1)); - } - - @Test - @Ignore("Fails on Bamboo") - public void loggingThatUsesJulIsCaptured() { - this.loggingSystem.beforeInitialize(); - this.loggingSystem.initialize(null, null, null); - java.util.logging.Logger julLogger = java.util.logging.Logger - .getLogger(getClass().getName()); - julLogger.severe("Hello world"); - String output = this.output.toString().trim(); - assertTrue("Wrong output:\n" + output, output.contains("Hello world")); - } - - @Test - public void bridgeHandlerLifecycle() { - assertFalse(bridgeHandlerInstalled()); - this.loggingSystem.beforeInitialize(); - assertTrue(bridgeHandlerInstalled()); - this.loggingSystem.cleanUp(); - assertFalse(bridgeHandlerInstalled()); - } - - private boolean bridgeHandlerInstalled() { - java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger(""); - Handler[] handlers = rootLogger.getHandlers(); - for (Handler handler : handlers) { - if (handler instanceof SLF4JBridgeHandler) { - return true; - } - } - return false; - } - -} diff --git a/spring-boot/src/test/resources/log4j-nondefault.properties b/spring-boot/src/test/resources/log4j-nondefault.properties deleted file mode 100644 index d852ca65d81..00000000000 --- a/spring-boot/src/test/resources/log4j-nondefault.properties +++ /dev/null @@ -1,10 +0,0 @@ -log4j.reset=true -log4j.rootCategory=INFO, CONSOLE - -PID=???? -LOG_PATTERN=${LOG_FILE} %d{yyyy-MM-dd HH:mm:ss.SSS}] service%X{context} - ${PID} %5p [%t] --- %c{1}: %m%n - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN}