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
4c51aa8e
Commit
4c51aa8e
authored
Oct 08, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
7287c66d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
44 additions
and
33 deletions
+44
-33
HealthIndicatorAutoConfiguration.java
...tuate/autoconfigure/HealthIndicatorAutoConfiguration.java
+1
-0
DiskSpaceHealthIndicatorProperties.java
...ot/actuate/health/DiskSpaceHealthIndicatorProperties.java
+3
-9
DiskSpaceHealthIndicatorTests.java
...rk/boot/actuate/health/DiskSpaceHealthIndicatorTests.java
+9
-10
HelloWorldService.java
...c/main/java/sample/actuator/log4j2/HelloWorldService.java
+1
-1
SampleActuatorApplication.java
...ava/sample/actuator/log4j2/SampleActuatorApplication.java
+1
-1
SampleController.java
...rc/main/java/sample/actuator/log4j2/SampleController.java
+1
-1
LoggingSystem.java
.../java/org/springframework/boot/logging/LoggingSystem.java
+2
-2
Log4J2LoggingSystem.java
...ingframework/boot/logging/log4j2/Log4J2LoggingSystem.java
+26
-9
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java
View file @
4c51aa8e
...
...
@@ -275,6 +275,7 @@ public class HealthIndicatorAutoConfiguration {
public
DiskSpaceHealthIndicatorProperties
diskSpaceHealthIndicatorProperties
()
{
return
new
DiskSpaceHealthIndicatorProperties
();
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorProperties.java
View file @
4c51aa8e
...
...
@@ -37,19 +37,12 @@ public class DiskSpaceHealthIndicatorProperties {
}
public
void
setPath
(
File
path
)
{
if
(!
path
.
exists
())
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path '%s' does not exist"
,
path
));
}
if
(!
path
.
canRead
())
{
throw
new
IllegalStateException
(
String
.
format
(
"Path '%s' cannot be read"
,
path
));
}
Assert
.
isTrue
(
path
.
exists
(),
"Path '"
+
path
+
"' does not exist"
);
Assert
.
isTrue
(
path
.
canRead
(),
"Path '"
+
path
+
"' cannot be read"
);
this
.
path
=
path
;
}
public
long
getThreshold
()
{
return
this
.
threshold
;
}
...
...
@@ -57,4 +50,5 @@ public class DiskSpaceHealthIndicatorProperties {
Assert
.
isTrue
(
threshold
>=
0
,
"threshold must be greater than 0"
);
this
.
threshold
=
threshold
;
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/DiskSpaceHealthIndicatorTests.java
View file @
4c51aa8e
...
...
@@ -27,7 +27,7 @@ import org.mockito.Mock;
import
org.mockito.runners.MockitoJUnitRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
wh
en
;
import
static
org
.
mockito
.
BDDMockito
.
giv
en
;
/**
* Tests for {@link DiskSpaceHealthIndicator}.
...
...
@@ -43,22 +43,21 @@ public class DiskSpaceHealthIndicatorTests {
public
ExpectedException
exception
=
ExpectedException
.
none
();
@Mock
File
fileMock
;
private
File
fileMock
;
HealthIndicator
healthIndicator
;
private
HealthIndicator
healthIndicator
;
@Before
public
void
setUp
()
throws
Exception
{
when
(
this
.
fileMock
.
exists
()).
then
Return
(
true
);
when
(
this
.
fileMock
.
canRead
()).
then
Return
(
true
);
given
(
this
.
fileMock
.
exists
()).
will
Return
(
true
);
given
(
this
.
fileMock
.
canRead
()).
will
Return
(
true
);
this
.
healthIndicator
=
new
DiskSpaceHealthIndicator
(
createProperties
(
this
.
fileMock
,
THRESHOLD_BYTES
));
}
@Test
public
void
diskSpaceIsUp
()
throws
Exception
{
when
(
this
.
fileMock
.
getFreeSpace
()).
thenReturn
(
THRESHOLD_BYTES
+
10
);
given
(
this
.
fileMock
.
getFreeSpace
()).
willReturn
(
THRESHOLD_BYTES
+
10
);
Health
health
=
this
.
healthIndicator
.
health
();
assertEquals
(
Status
.
UP
,
health
.
getStatus
());
assertEquals
(
THRESHOLD_BYTES
,
health
.
getDetails
().
get
(
"threshold"
));
...
...
@@ -67,8 +66,7 @@ public class DiskSpaceHealthIndicatorTests {
@Test
public
void
diskSpaceIsDown
()
throws
Exception
{
when
(
this
.
fileMock
.
getFreeSpace
()).
thenReturn
(
THRESHOLD_BYTES
-
10
);
given
(
this
.
fileMock
.
getFreeSpace
()).
willReturn
(
THRESHOLD_BYTES
-
10
);
Health
health
=
this
.
healthIndicator
.
health
();
assertEquals
(
Status
.
DOWN
,
health
.
getStatus
());
assertEquals
(
THRESHOLD_BYTES
,
health
.
getDetails
().
get
(
"threshold"
));
...
...
@@ -81,4 +79,5 @@ public class DiskSpaceHealthIndicatorTests {
properties
.
setThreshold
(
threshold
);
return
properties
;
}
}
\ No newline at end of file
}
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/HelloWorldService.java
View file @
4c51aa8e
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
4
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.
...
...
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorApplication.java
View file @
4c51aa8e
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
4
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.
...
...
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleController.java
View file @
4c51aa8e
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
4
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.
...
...
spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java
View file @
4c51aa8e
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
4
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.
...
...
@@ -38,7 +38,7 @@ public abstract class LoggingSystem {
systems
.
put
(
"org.apache.log4j.PropertyConfigurator"
,
pkg
+
".log4j.Log4JLoggingSystem"
);
systems
.
put
(
"org.apache.logging.log4j.LogManager"
,
pkg
+
".log4j2.Log4J2LoggingSystem"
);
+
".log4j2.Log4J2LoggingSystem"
);
systems
.
put
(
"java.util.logging.LogManager"
,
pkg
+
".java.JavaLoggingSystem"
);
SYSTEMS
=
Collections
.
unmodifiableMap
(
systems
);
}
...
...
spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java
View file @
4c51aa8e
/*
* 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
org
.
springframework
.
boot
.
logging
.
log4j2
;
import
java.net.URL
;
...
...
@@ -47,22 +63,22 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
public
void
initialize
(
String
configLocation
)
{
Assert
.
notNull
(
configLocation
,
"ConfigLocation must not be null"
);
String
resolvedLocation
=
SystemPropertyUtils
.
resolvePlaceholders
(
configLocation
);
try
{
LoggerContext
ctx
=
(
LoggerContext
)
LogManager
.
getContext
(
false
);
URL
url
=
ResourceUtils
.
getURL
(
resolvedLocation
);
ConfigurationSource
configSource
=
new
ConfigurationSource
(
url
.
openStream
(),
url
);
Configuration
config
=
ConfigurationFactory
.
getInstance
().
getConfiguration
(
configSource
);
ctx
.
start
(
config
);
initializeAndStart
(
resolvedLocation
);
}
catch
(
Exception
ex
)
{
throw
new
IllegalStateException
(
"Could not initialize logging from "
+
configLocation
,
ex
);
}
}
private
void
initializeAndStart
(
String
resolvedLocation
)
throws
Exception
{
LoggerContext
ctx
=
(
LoggerContext
)
LogManager
.
getContext
(
false
);
URL
url
=
ResourceUtils
.
getURL
(
resolvedLocation
);
ConfigurationSource
configSource
=
new
ConfigurationSource
(
url
.
openStream
(),
url
);
Configuration
config
=
ConfigurationFactory
.
getInstance
().
getConfiguration
(
configSource
);
ctx
.
start
(
config
);
}
@Override
...
...
@@ -71,4 +87,5 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
ctx
.
getConfiguration
().
getLoggerConfig
(
loggerName
).
setLevel
(
LEVELS
.
get
(
level
));
ctx
.
updateLoggers
();
}
}
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