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
40abd138
Commit
40abd138
authored
Dec 16, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be defensive about hiding log errors
Ensure that log configuration errors always get reported.
parent
528fcf3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
1 deletion
+32
-1
LoggedExceptionHandler.java
...java/org/springframework/boot/LoggedExceptionHandler.java
+32
-1
No files found.
spring-boot/src/main/java/org/springframework/boot/LoggedExceptionHandler.java
View file @
40abd138
...
...
@@ -19,7 +19,10 @@ package org.springframework.boot;
import
java.lang.Thread.UncaughtExceptionHandler
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* {@link UncaughtExceptionHandler} to suppress handling already logged exceptions.
...
...
@@ -28,6 +31,14 @@ import java.util.List;
*/
class
LoggedExceptionHandler
implements
UncaughtExceptionHandler
{
private
static
Set
<
String
>
LOG_CONFIGURATION_MESSAGES
;
static
{
Set
<
String
>
messages
=
new
HashSet
<
String
>();
messages
.
add
(
"Logback configuration error detected"
);
LOG_CONFIGURATION_MESSAGES
=
Collections
.
unmodifiableSet
(
messages
);
}
private
static
LoggedExceptionHandlerThreadLocal
handler
=
new
LoggedExceptionHandlerThreadLocal
();
private
final
UncaughtExceptionHandler
parent
;
...
...
@@ -45,7 +56,7 @@ class LoggedExceptionHandler implements UncaughtExceptionHandler {
@Override
public
void
uncaughtException
(
Thread
thread
,
Throwable
ex
)
{
try
{
if
(
!
isRegistered
(
ex
)
&&
this
.
parent
!=
null
)
{
if
(
isPassedToParent
(
ex
)
&&
this
.
parent
!=
null
)
{
this
.
parent
.
uncaughtException
(
thread
,
ex
);
}
}
...
...
@@ -54,6 +65,26 @@ class LoggedExceptionHandler implements UncaughtExceptionHandler {
}
}
private
boolean
isPassedToParent
(
Throwable
ex
)
{
return
isLogConfigurationMessage
(
ex
)
||
!
isRegistered
(
ex
);
}
/**
* Check if the exception is a log configuration message, i.e. the log call might not
* have actually output anything.
*/
private
boolean
isLogConfigurationMessage
(
Throwable
ex
)
{
String
message
=
ex
.
getMessage
();
if
(
message
!=
null
)
{
for
(
String
candidate
:
LOG_CONFIGURATION_MESSAGES
)
{
if
(
message
.
contains
(
candidate
))
{
return
true
;
}
}
}
return
false
;
}
private
boolean
isRegistered
(
Throwable
ex
)
{
if
(
this
.
exceptions
.
contains
(
ex
))
{
return
true
;
...
...
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