Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3ed5a723
Commit
3ed5a723
authored
Dec 30, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish log4j2 sample
parent
c230a21a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
161 deletions
+47
-161
pom.xml
...g-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml
+12
-8
HelloWorldService.java
...c/main/java/sample/actuator/log4j2/HelloWorldService.java
+0
-32
SampleController.java
...rc/main/java/sample/actuator/log4j2/SampleController.java
+0
-47
ServiceProperties.java
...c/main/java/sample/actuator/log4j2/ServiceProperties.java
+0
-36
application.properties
...actuator-log4j2/src/main/resources/application.properties
+2
-17
log4j2.xml
...boot-sample-actuator-log4j2/src/main/resources/log4j2.xml
+1
-2
SampleActuatorLog4J2ApplicationTests.java
...actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java
+32
-19
No files found.
spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml
View file @
3ed5a723
...
...
@@ -21,7 +21,7 @@
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
-actuator
</artifactId>
<artifactId>
spring-boot-starter
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -29,24 +29,28 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-log4j2
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-log4j2
</artifactId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
...
...
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/HelloWorldService.java
deleted
100644 → 0
View file @
c230a21a
/*
* 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.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
();
}
}
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleController.java
deleted
100644 → 0
View file @
c230a21a
/*
* 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.
* 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.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
@Controller
public
class
SampleController
{
@Autowired
private
HelloWorldService
helloWorldService
;
@GetMapping
(
"/"
)
@ResponseBody
public
Map
<
String
,
String
>
helloWorld
()
{
return
Collections
.
singletonMap
(
"message"
,
this
.
helloWorldService
.
getHelloMessage
());
}
@RequestMapping
(
"/foo"
)
@ResponseBody
public
String
foo
()
{
throw
new
IllegalArgumentException
(
"Server error"
);
}
}
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/ServiceProperties.java
deleted
100644 → 0
View file @
c230a21a
/*
* 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
;
}
}
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/application.properties
View file @
3ed5a723
#logging.file=/tmp/logs/app.log
#server.port=8080
#management.port=8080
management.address
=
127.0.0.1
management.shell.ssh.enabled
=
true
management.shell.ssh.port
=
2222
#management.shell.telnet.enabled=false
#management.shell.telnet.port=1111
management.shell.auth.type
=
spring
#management.shell.auth.type=key
#management.shell.auth.key.path=${user.home}/test/id_rsa.pub.pem
#management.shell.auth.type=simple
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
management.security.enabled
=
false
\ No newline at end of file
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/log4j2.xml
View file @
3ed5a723
...
...
@@ -2,7 +2,7 @@
<Configuration
status=
"WARN"
monitorInterval=
"30"
>
<Properties>
<Property
name=
"PID"
>
????
</Property>
<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>
<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%
x
wEx
</Property>
</Properties>
<Appenders>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
follow=
"true"
>
...
...
@@ -13,7 +13,6 @@
<Logger
name=
"org.hibernate.validator.internal.util.Version"
level=
"warn"
/>
<Logger
name=
"org.apache.coyote.http11.Http11NioProtocol"
level=
"warn"
/>
<Logger
name=
"org.apache.tomcat.util.net.NioSelectorPool"
level=
"warn"
/>
<Logger
name=
"org.apache.catalina.startup.DigesterFactory"
level=
"error"
/>
<Root
level=
"info"
>
<AppenderRef
ref=
"Console"
/>
...
...
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java
View file @
3ed5a723
...
...
@@ -16,43 +16,56 @@
package
sample
.
actuator
.
log4j2
;
import
java.util.Map
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.boot.test.rule.OutputCapture
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/**
*
Basic integration tests for service demo application
.
*
Tests for {@link SampleActuatorLog4J2Application}
.
*
* @author Dave Syer
* @@author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
)
@
DirtiesContext
@SpringBootTest
@
AutoConfigureMockMvc
public
class
SampleActuatorLog4J2ApplicationTests
{
private
static
final
Logger
logger
=
LogManager
.
getLogger
(
SampleActuatorLog4J2ApplicationTests
.
class
);
@Rule
public
OutputCapture
output
=
new
OutputCapture
();
@Autowired
private
TestRestTemplate
restTemplate
;
private
MockMvc
mvc
;
@Test
public
void
testLogger
()
{
logger
.
info
(
"Hello World"
);
this
.
output
.
expect
(
containsString
(
"Hello World"
));
}
@Test
public
void
testHome
()
throws
Exception
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Daniel"
);
public
void
validateLoggersEndpoint
()
throws
Exception
{
this
.
mvc
.
perform
(
get
(
"/loggers/org.apache.coyote.http11.Http11NioProtocol"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
equalTo
(
"{\"configuredLevel\":\"WARN\","
+
"\"effectiveLevel\":\"WARN\"}"
)));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment