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
5e7dbe8f
Commit
5e7dbe8f
authored
Sep 14, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move configuration of LogFileWebEndpoint
See gh-10263
parent
d7f30081
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
16 deletions
+94
-16
LogFileWebEndpointManagementContextConfiguration.java
...ing/LogFileWebEndpointManagementContextConfiguration.java
+10
-1
LogFileWebEndpointProperties.java
...e/autoconfigure/logging/LogFileWebEndpointProperties.java
+47
-0
LogFileWebEndpointManagementContextConfigurationTests.java
...ogFileWebEndpointManagementContextConfigurationTests.java
+30
-0
LogFileWebEndpoint.java
...ringframework/boot/actuate/logger/LogFileWebEndpoint.java
+4
-13
LogFileWebEndpointTests.java
...ramework/boot/actuate/logger/LogFileWebEndpointTests.java
+3
-2
No files found.
spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointManagementContextConfiguration.java
View file @
5e7dbe8f
...
@@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionMessage;
...
@@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import
org.springframework.boot.autoconfigure.condition.ConditionOutcome
;
import
org.springframework.boot.autoconfigure.condition.ConditionOutcome
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.SpringBootCondition
;
import
org.springframework.boot.autoconfigure.condition.SpringBootCondition
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Conditional
;
...
@@ -36,13 +37,21 @@ import org.springframework.util.StringUtils;
...
@@ -36,13 +37,21 @@ import org.springframework.util.StringUtils;
* @since 2.0.0
* @since 2.0.0
*/
*/
@ManagementContextConfiguration
@ManagementContextConfiguration
@EnableConfigurationProperties
(
LogFileWebEndpointProperties
.
class
)
public
class
LogFileWebEndpointManagementContextConfiguration
{
public
class
LogFileWebEndpointManagementContextConfiguration
{
private
final
LogFileWebEndpointProperties
properties
;
public
LogFileWebEndpointManagementContextConfiguration
(
LogFileWebEndpointProperties
properties
)
{
this
.
properties
=
properties
;
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
@Conditional
(
LogFileCondition
.
class
)
@Conditional
(
LogFileCondition
.
class
)
public
LogFileWebEndpoint
logFileWebEndpoint
(
Environment
environment
)
{
public
LogFileWebEndpoint
logFileWebEndpoint
(
Environment
environment
)
{
return
new
LogFileWebEndpoint
(
environment
);
return
new
LogFileWebEndpoint
(
environment
,
this
.
properties
.
getExternalFile
()
);
}
}
private
static
class
LogFileCondition
extends
SpringBootCondition
{
private
static
class
LogFileCondition
extends
SpringBootCondition
{
...
...
spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointProperties.java
0 → 100644
View file @
5e7dbe8f
/*
* Copyright 2012-2017 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
.
autoconfigure
.
logging
;
import
java.io.File
;
import
org.springframework.boot.actuate.logger.LogFileWebEndpoint
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Configuration properties for {@link LogFileWebEndpoint}.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
@ConfigurationProperties
(
prefix
=
"endpoints.logfile"
)
public
class
LogFileWebEndpointProperties
{
/**
* External Logfile to be accessed. Can be used if the logfile is written by output
* redirect and not by the logging system itself.
*/
private
File
externalFile
;
public
File
getExternalFile
()
{
return
this
.
externalFile
;
}
public
void
setExternalFile
(
File
externalFile
)
{
this
.
externalFile
=
externalFile
;
}
}
spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointManagementContextConfigurationTests.java
View file @
5e7dbe8f
...
@@ -16,10 +16,19 @@
...
@@ -16,10 +16,19 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
logging
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
logging
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
org.springframework.boot.actuate.logger.LogFileWebEndpoint
;
import
org.springframework.boot.actuate.logger.LogFileWebEndpoint
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.core.io.Resource
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.StreamUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -32,6 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -32,6 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
public
class
LogFileWebEndpointManagementContextConfigurationTests
{
public
class
LogFileWebEndpointManagementContextConfigurationTests
{
@Rule
public
TemporaryFolder
temp
=
new
TemporaryFolder
();
private
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
private
WebApplicationContextRunner
contextRunner
=
new
WebApplicationContextRunner
()
.
withUserConfiguration
(
.
withUserConfiguration
(
LogFileWebEndpointManagementContextConfiguration
.
class
);
LogFileWebEndpointManagementContextConfiguration
.
class
);
...
@@ -65,4 +78,21 @@ public class LogFileWebEndpointManagementContextConfigurationTests {
...
@@ -65,4 +78,21 @@ public class LogFileWebEndpointManagementContextConfigurationTests {
.
hasSingleBean
(
LogFileWebEndpoint
.
class
));
.
hasSingleBean
(
LogFileWebEndpoint
.
class
));
}
}
@Test
public
void
logFileWebEndpointUsesConfiguredExternalFile
()
throws
IOException
{
File
file
=
this
.
temp
.
newFile
(
"logfile"
);
FileCopyUtils
.
copy
(
"--TEST--"
.
getBytes
(),
file
);
this
.
contextRunner
.
withPropertyValues
(
"endpoints.logfile.external-file:"
+
file
.
getAbsolutePath
()).
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
LogFileWebEndpoint
.
class
);
LogFileWebEndpoint
endpoint
=
context
.
getBean
(
LogFileWebEndpoint
.
class
);
Resource
resource
=
endpoint
.
logFile
();
assertThat
(
resource
).
isNotNull
();
assertThat
(
StreamUtils
.
copyToString
(
resource
.
getInputStream
(),
StandardCharsets
.
UTF_8
)).
isEqualTo
(
"--TEST--"
);
});
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/logger/LogFileWebEndpoint.java
View file @
5e7dbe8f
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.LogFactory;
...
@@ -24,7 +24,6 @@ import org.apache.commons.logging.LogFactory;
import
org.springframework.boot.actuate.endpoint.EndpointExposure
;
import
org.springframework.boot.actuate.endpoint.EndpointExposure
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.Endpoint
;
import
org.springframework.boot.actuate.endpoint.annotation.ReadOperation
;
import
org.springframework.boot.actuate.endpoint.annotation.ReadOperation
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.logging.LogFile
;
import
org.springframework.boot.logging.LogFile
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.core.io.FileSystemResource
;
...
@@ -38,7 +37,6 @@ import org.springframework.core.io.Resource;
...
@@ -38,7 +37,6 @@ import org.springframework.core.io.Resource;
* @author Andy Wilkinson
* @author Andy Wilkinson
* @since 2.0.0
* @since 2.0.0
*/
*/
@ConfigurationProperties
(
prefix
=
"endpoints.logfile"
)
@Endpoint
(
id
=
"logfile"
,
exposure
=
EndpointExposure
.
WEB
)
@Endpoint
(
id
=
"logfile"
,
exposure
=
EndpointExposure
.
WEB
)
public
class
LogFileWebEndpoint
{
public
class
LogFileWebEndpoint
{
...
@@ -46,22 +44,15 @@ public class LogFileWebEndpoint {
...
@@ -46,22 +44,15 @@ public class LogFileWebEndpoint {
private
final
Environment
environment
;
private
final
Environment
environment
;
/**
* External Logfile to be accessed. Can be used if the logfile is written by output
* redirect and not by the logging system itself.
*/
private
File
externalFile
;
private
File
externalFile
;
public
LogFileWebEndpoint
(
Environment
environment
)
{
public
LogFileWebEndpoint
(
Environment
environment
,
File
externalFile
)
{
this
.
environment
=
environment
;
this
.
environment
=
environment
;
this
.
externalFile
=
externalFile
;
}
}
public
File
getExternalFile
()
{
public
LogFileWebEndpoint
(
Environment
environment
)
{
return
this
.
externalFile
;
this
(
environment
,
null
);
}
public
void
setExternalFile
(
File
externalFile
)
{
this
.
externalFile
=
externalFile
;
}
}
@ReadOperation
@ReadOperation
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logger/LogFileWebEndpointTests.java
View file @
5e7dbe8f
...
@@ -78,8 +78,9 @@ public class LogFileWebEndpointTests {
...
@@ -78,8 +78,9 @@ public class LogFileWebEndpointTests {
@Test
@Test
public
void
resourceResponseWithExternalLogFile
()
throws
Exception
{
public
void
resourceResponseWithExternalLogFile
()
throws
Exception
{
this
.
endpoint
.
setExternalFile
(
this
.
logFile
);
LogFileWebEndpoint
endpoint
=
new
LogFileWebEndpoint
(
this
.
environment
,
Resource
resource
=
this
.
endpoint
.
logFile
();
this
.
logFile
);
Resource
resource
=
endpoint
.
logFile
();
assertThat
(
resource
).
isNotNull
();
assertThat
(
resource
).
isNotNull
();
assertThat
(
StreamUtils
.
copyToString
(
resource
.
getInputStream
(),
assertThat
(
StreamUtils
.
copyToString
(
resource
.
getInputStream
(),
StandardCharsets
.
UTF_8
)).
isEqualTo
(
"--TEST--"
);
StandardCharsets
.
UTF_8
)).
isEqualTo
(
"--TEST--"
);
...
...
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