diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml
index 2237d252c6..bbcfc86385 100644
--- a/spring-boot-dependencies/pom.xml
+++ b/spring-boot-dependencies/pom.xml
@@ -93,6 +93,7 @@
4.11
3.0.8
1.2.17
+ 2.0.2
1.1.2
1.9.5
2.12.3
@@ -287,6 +288,11 @@
spring-boot-starter-log4j
1.2.0.BUILD-SNAPSHOT
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+ 1.2.0.BUILD-SNAPSHOT
+
org.springframework.boot
spring-boot-starter-logging
@@ -562,6 +568,21 @@
log4j
${log4j.version}
+
+ org.apache.logging.log4j
+ log4j-api
+ ${log4j2.version}
+
+
+ org.apache.logging.log4j
+ log4j-core
+ ${log4j2.version}
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ ${log4j2.version}
+
mysql
mysql-connector-java
diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc
index c597a2011a..b2bbc3e9f0 100644
--- a/spring-boot-docs/src/main/asciidoc/howto.adoc
+++ b/spring-boot-docs/src/main/asciidoc/howto.adoc
@@ -961,14 +961,15 @@ If Groovy is on the classpath you should be able to configure Logback with
[[howto-configure-log4j-for-logging]]
=== Configure Log4j for logging
-Spring Boot supports http://logging.apache.org/log4j[Log4j] for logging
-configuration, but it has to be on the classpath. If you are using the starter poms for
-assembling dependencies that means you have to exclude logback and then include log4j
-instead. If you aren't using the starter poms then you need to provide `commons-logging`
-(at least) in addition to Log4j.
+Spring Boot also supports either http://logging.apache.org/log4j/1.2[Log4j] or
+http://logging.apache.org/log4j/2.x[Log4j 2] for logging configuration, but only if one
+of them is on the classpath. If you are using the starter poms for assembling
+dependencies that means you have to exclude Logback and then include your chosen version
+of Log4j instead. If you aren't using the starter poms then you need to provide
+`commons-logging` (at least) in addition to your chosen version of Log4j.
-The simplest path to using Log4j is probably through the starter poms, even though it
-requires some jiggling with excludes, e.g. in Maven:
+The simplest path is probably through the starter poms, even though it requires some
+jiggling with excludes, .e.g. in Maven:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
@@ -992,10 +993,13 @@ requires some jiggling with excludes, e.g. in Maven:
----
-NOTE: The use of the log4j starter gathers together the dependencies for common logging
-requirements (e.g. including having Tomcat use `java.util.logging` but configure the
-output using Log4j). See the Actuator Log4j Sample for more detail and to see it in
-action.
+To use Log4j 2, simply depend on `spring-boot-starter-log4j2` rather than
+`spring-boot-starter-log4j`
+
+NOTE: The use of the one of the Log4j starters gathers together the dependencies for
+common logging requirements (e.g. including having Tomcat use `java.util.logging` but
+configure the output using Log4j or Log4j 2). See the Actuator Log4j or Log4j 2
+samples for more detail and to see it in action.
diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml
index ac005c1d09..a7ec0496a6 100644
--- a/spring-boot-samples/pom.xml
+++ b/spring-boot-samples/pom.xml
@@ -22,6 +22,7 @@
spring-boot-sample-actuator
spring-boot-sample-actuator-log4j
+ spring-boot-sample-actuator-log4j2
spring-boot-sample-actuator-noweb
spring-boot-sample-actuator-ui
spring-boot-sample-amqp
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-log4j/pom.xml
index 64261d0d7d..1db124f8d9 100644
--- a/spring-boot-samples/spring-boot-sample-actuator-log4j/pom.xml
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j/pom.xml
@@ -8,8 +8,8 @@
1.2.0.BUILD-SNAPSHOT
spring-boot-sample-actuator-log4j
- Spring Boot Actuator Log4J Sample
- Spring Boot Actuator Log4J Sample
+ Spring Boot Actuator Log4j Sample
+ Spring Boot Actuator Log4j Sample
http://projects.spring.io/spring-boot/
Pivotal Software, Inc.
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml
new file mode 100644
index 0000000000..43b4316113
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml
@@ -0,0 +1,60 @@
+
+
+ 4.0.0
+
+
+ org.springframework.boot
+ spring-boot-samples
+ 1.2.0.BUILD-SNAPSHOT
+
+ spring-boot-sample-actuator-log4j2
+ Spring Boot Actuator Log4j 2 Sample
+ Spring Boot Actuator Log4j 2 Sample
+ http://projects.spring.io/spring-boot/
+
+ Pivotal Software, Inc.
+ http://www.spring.io
+
+
+ ${basedir}/../..
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-log4j2
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/HelloWorldService.java
new file mode 100644
index 0000000000..fe8211ed48
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/HelloWorldService.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012-2013 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 sample.actuator.log4j2;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class HelloWorldService {
+
+ @Autowired
+ private ServiceProperties configuration;
+
+ public String getHelloMessage() {
+ return "Hello " + this.configuration.getName();
+ }
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorApplication.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorApplication.java
new file mode 100644
index 0000000000..5dd9d4569f
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorApplication.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012-2013 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 sample.actuator.log4j2;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@EnableAutoConfiguration
+@EnableConfigurationProperties
+@ComponentScan
+public class SampleActuatorApplication {
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(SampleActuatorApplication.class, args);
+ }
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleController.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleController.java
new file mode 100644
index 0000000000..889931dc89
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleController.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2012-2013 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 sample.actuator.log4j2;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+public class SampleController {
+
+ @Autowired
+ private HelloWorldService helloWorldService;
+
+ @RequestMapping("/")
+ @ResponseBody
+ public Map helloWorld() {
+ return Collections.singletonMap("message",
+ this.helloWorldService.getHelloMessage());
+ }
+
+ @RequestMapping("/foo")
+ @ResponseBody
+ public String foo() {
+ throw new IllegalArgumentException("Server error");
+ }
+}
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/ServiceProperties.java
new file mode 100644
index 0000000000..94945534a2
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/ServiceProperties.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012-2014 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 sample.actuator.log4j2;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false)
+@Component
+public class ServiceProperties {
+
+ private String name = "World";
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/application.properties
new file mode 100644
index 0000000000..0f0b272726
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/application.properties
@@ -0,0 +1,17 @@
+logging.file: /tmp/logs/app.log
+#server.port: 8080
+#management.port: 8080
+management.address: 127.0.0.1
+endpoints.shutdown.enabled: true
+server.tomcat.basedir: target/tomcat
+server.tomcat.access_log_pattern: %h %t "%r" %s %b
+security.require_ssl: false
+service.name: Daniel
+shell.ssh.enabled: true
+shell.ssh.port: 2222
+#shell.telnet.enabled: false
+#shell.telnet.port: 1111
+shell.auth: spring
+#shell.auth: key
+#shell.auth.key.path: ${user.home}/test/id_rsa.pub.pem
+#shell.auth: simple
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/log4j2.xml b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/log4j2.xml
new file mode 100644
index 0000000000..0f526e7079
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/log4j2.xml
@@ -0,0 +1,22 @@
+
+
+
+ ????
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] log4j2%X{context} - ${sys:PID} %5p [%t] --- %c{1}: %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java
new file mode 100644
index 0000000000..ad5c29a82c
--- /dev/null
+++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2012-2014 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 sample.actuator.log4j2;
+
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.IntegrationTest;
+import org.springframework.boot.test.SpringApplicationConfiguration;
+import org.springframework.boot.test.TestRestTemplate;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Basic integration tests for service demo application.
+ *
+ * @author Dave Syer
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringApplicationConfiguration(classes = SampleActuatorApplication.class)
+@WebAppConfiguration
+@IntegrationTest("server.port=0")
+@DirtiesContext
+public class SampleActuatorApplicationTests {
+
+ @Value("${local.server.port}")
+ private int port;
+
+ @Test
+ public void testHome() throws Exception {
+ @SuppressWarnings("rawtypes")
+ ResponseEntity