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
53d9aa60
Commit
53d9aa60
authored
Apr 27, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4836 from joshiste/issue-4255
* pr/4836: Add external-file-property to LogFileMvcEndpoint
parents
79c163c6
49ef9360
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
9 deletions
+44
-9
EndpointWebMvcManagementContextConfiguration.java
...nfigure/EndpointWebMvcManagementContextConfiguration.java
+8
-1
LogFileMvcEndpoint.java
...amework/boot/actuate/endpoint/mvc/LogFileMvcEndpoint.java
+25
-8
LogFileMvcEndpointTests.java
...rk/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java
+11
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java
View file @
53d9aa60
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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,6 +40,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.SpringBootCondition
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ConditionContext
;
...
...
@@ -180,6 +181,12 @@ public class EndpointWebMvcManagementContextConfiguration {
if
(
StringUtils
.
hasText
(
config
))
{
return
ConditionOutcome
.
match
(
"Found logging.path: "
+
config
);
}
config
=
new
RelaxedPropertyResolver
(
environment
,
"endpoints.logfile."
)
.
getProperty
(
"external-file"
);
if
(
StringUtils
.
hasText
(
config
))
{
return
ConditionOutcome
.
match
(
"Found endpoints.logfile.external-file: "
+
config
);
}
return
ConditionOutcome
.
noMatch
(
"Found no log file configuration"
);
}
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/LogFileMvcEndpoint.java
View file @
53d9aa60
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
.
mvc
;
import
java.io.File
;
import
java.io.IOException
;
import
javax.servlet.ServletException
;
...
...
@@ -72,6 +73,12 @@ public class LogFileMvcEndpoint implements MvcEndpoint, EnvironmentAware {
*/
private
Boolean
sensitive
;
/**
* 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
Environment
environment
;
@Override
...
...
@@ -105,6 +112,14 @@ public class LogFileMvcEndpoint implements MvcEndpoint, EnvironmentAware {
this
.
sensitive
=
sensitive
;
}
public
File
getExternalFile
()
{
return
this
.
externalFile
;
}
public
void
setExternalFile
(
File
externalFile
)
{
this
.
externalFile
=
externalFile
;
}
@Override
@SuppressWarnings
(
"rawtypes"
)
public
Class
<?
extends
Endpoint
>
getEndpointType
()
{
...
...
@@ -119,23 +134,25 @@ public class LogFileMvcEndpoint implements MvcEndpoint, EnvironmentAware {
return
;
}
Resource
resource
=
getLogFileResource
();
if
(
resource
!=
null
&&
!
resource
.
exists
())
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Log file '"
+
resource
+
"' does not exist"
);
}
resource
=
null
;
}
new
Handler
(
resource
).
handleRequest
(
request
,
response
);
}
private
Resource
getLogFileResource
()
{
if
(
this
.
externalFile
!=
null
)
{
return
new
FileSystemResource
(
this
.
externalFile
);
}
LogFile
logFile
=
LogFile
.
get
(
this
.
environment
);
if
(
logFile
==
null
)
{
logger
.
debug
(
"Missing 'logging.file' or 'logging.path' properties"
);
return
null
;
}
FileSystemResource
resource
=
new
FileSystemResource
(
logFile
.
toString
());
if
(!
resource
.
exists
())
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Log file '"
+
resource
+
"' does not exist"
);
}
return
null
;
}
return
resource
;
return
new
FileSystemResource
(
logFile
.
toString
());
}
/**
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LogFileMvcEndpointTests.java
View file @
53d9aa60
...
...
@@ -110,4 +110,15 @@ public class LogFileMvcEndpointTests {
assertThat
(
response
.
getContentAsString
()).
isEqualTo
(
"--TEST--"
);
}
@Test
public
void
invokeGetsContentExternalFile
()
throws
Exception
{
this
.
mvc
.
setExternalFile
(
this
.
logFile
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
HttpMethod
.
GET
.
name
(),
"/logfile"
);
this
.
mvc
.
invoke
(
request
,
response
);
assertThat
(
response
.
getStatus
()).
isEqualTo
(
HttpStatus
.
OK
.
value
());
assertThat
(
"--TEST--"
).
isEqualTo
(
response
.
getContentAsString
());
}
}
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