Skip to content

Commit 9dfaf4d

Browse files
committed
Merge branch '1.5.x'
2 parents 0b67a89 + 3ed5a72 commit 9dfaf4d

File tree

7 files changed

+47
-153
lines changed

7 files changed

+47
-153
lines changed

spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml

+12-8
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,36 @@
2121
<dependencies>
2222
<dependency>
2323
<groupId>org.springframework.boot</groupId>
24-
<artifactId>spring-boot-starter-actuator</artifactId>
24+
<artifactId>spring-boot-starter</artifactId>
2525
<exclusions>
2626
<exclusion>
2727
<groupId>org.springframework.boot</groupId>
2828
<artifactId>spring-boot-starter-logging</artifactId>
2929
</exclusion>
3030
</exclusions>
3131
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-log4j2</artifactId>
35+
</dependency>
36+
3237
<dependency>
3338
<groupId>org.springframework.boot</groupId>
3439
<artifactId>spring-boot-starter-web</artifactId>
3540
</dependency>
3641
<dependency>
3742
<groupId>org.springframework.boot</groupId>
38-
<artifactId>spring-boot-starter-log4j2</artifactId>
43+
<artifactId>spring-boot-starter-actuator</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-security</artifactId>
3948
</dependency>
49+
4050
<dependency>
4151
<groupId>org.springframework.boot</groupId>
4252
<artifactId>spring-boot-starter-test</artifactId>
4353
<scope>test</scope>
44-
<exclusions>
45-
<exclusion>
46-
<groupId>org.springframework.boot</groupId>
47-
<artifactId>spring-boot-starter-logging</artifactId>
48-
</exclusion>
49-
</exclusions>
5054
</dependency>
5155
</dependencies>
5256
<build>

spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/HelloWorldService.java

-32
This file was deleted.

spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleController.java

-47
This file was deleted.

spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/ServiceProperties.java

-36
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
#logging.file=/tmp/logs/app.log
2-
#server.port=8080
3-
#management.port=8080
4-
management.address=127.0.0.1
5-
61
endpoints.shutdown.enabled=true
7-
server.tomcat.basedir=target/tomcat
8-
server.tomcat.access_log_pattern=%h %t "%r" %s %b
9-
security.require_ssl=false
10-
service.name=Daniel
2+
3+
management.security.enabled=false

spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/log4j2.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Configuration status="WARN" monitorInterval="30">
33
<Properties>
44
<Property name="PID">????</Property>
5-
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%wEx</Property>
5+
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx</Property>
66
</Properties>
77
<Appenders>
88
<Console name="Console" target="SYSTEM_OUT" follow="true">
@@ -13,7 +13,6 @@
1313
<Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
1414
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
1515
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
16-
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
1716

1817
<Root level="info">
1918
<AppenderRef ref="Console"/>

spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java

+32-19
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,56 @@
1616

1717
package sample.actuator.log4j2;
1818

19-
import java.util.Map;
20-
19+
import org.apache.logging.log4j.LogManager;
20+
import org.apache.logging.log4j.Logger;
21+
import org.junit.Rule;
2122
import org.junit.Test;
2223
import org.junit.runner.RunWith;
2324

2425
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
2527
import org.springframework.boot.test.context.SpringBootTest;
26-
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
27-
import org.springframework.boot.test.web.client.TestRestTemplate;
28-
import org.springframework.http.HttpStatus;
29-
import org.springframework.http.ResponseEntity;
30-
import org.springframework.test.annotation.DirtiesContext;
28+
import org.springframework.boot.test.rule.OutputCapture;
3129
import org.springframework.test.context.junit4.SpringRunner;
30+
import org.springframework.test.web.servlet.MockMvc;
3231

33-
import static org.assertj.core.api.Assertions.assertThat;
32+
import static org.hamcrest.Matchers.containsString;
33+
import static org.hamcrest.Matchers.equalTo;
34+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
35+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
36+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
3437

3538
/**
36-
* Basic integration tests for service demo application.
39+
* Tests for {@link SampleActuatorLog4J2Application}.
3740
*
3841
* @author Dave Syer
42+
* @@author Stephane Nicoll
3943
*/
4044
@RunWith(SpringRunner.class)
41-
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
42-
@DirtiesContext
45+
@SpringBootTest
46+
@AutoConfigureMockMvc
4347
public class SampleActuatorLog4J2ApplicationTests {
4448

49+
private static final Logger logger = LogManager.getLogger(SampleActuatorLog4J2ApplicationTests.class);
50+
51+
@Rule
52+
public OutputCapture output = new OutputCapture();
53+
4554
@Autowired
46-
private TestRestTemplate restTemplate;
55+
private MockMvc mvc;
56+
57+
@Test
58+
public void testLogger() {
59+
logger.info("Hello World");
60+
this.output.expect(containsString("Hello World"));
61+
}
4762

4863
@Test
49-
public void testHome() throws Exception {
50-
@SuppressWarnings("rawtypes")
51-
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class);
52-
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
53-
@SuppressWarnings("unchecked")
54-
Map<String, Object> body = entity.getBody();
55-
assertThat(body.get("message")).isEqualTo("Hello Daniel");
64+
public void validateLoggersEndpoint() throws Exception {
65+
this.mvc.perform(get("/loggers/org.apache.coyote.http11.Http11NioProtocol"))
66+
.andExpect(status().isOk())
67+
.andExpect(content().string(equalTo(
68+
"{\"configuredLevel\":\"WARN\"," + "\"effectiveLevel\":\"WARN\"}")));
5669
}
5770

5871
}

0 commit comments

Comments
 (0)