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
e1ad5641
Commit
e1ad5641
authored
Nov 27, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Trim whitespace when coercing to a LogLevel"
Closes gh-15143
parent
dfe94a0a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
LoggingApplicationListener.java
...work/boot/context/logging/LoggingApplicationListener.java
+5
-4
LoggingApplicationListenerTests.java
...boot/context/logging/LoggingApplicationListenerTests.java
+13
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java
View file @
e1ad5641
...
@@ -364,18 +364,19 @@ public class LoggingApplicationListener implements GenericApplicationListener {
...
@@ -364,18 +364,19 @@ public class LoggingApplicationListener implements GenericApplicationListener {
private
void
setLogLevel
(
LoggingSystem
system
,
String
name
,
String
level
)
{
private
void
setLogLevel
(
LoggingSystem
system
,
String
name
,
String
level
)
{
try
{
try
{
name
=
name
.
equalsIgnoreCase
(
LoggingSystem
.
ROOT_LOGGER_NAME
)
?
null
:
name
;
name
=
name
.
equalsIgnoreCase
(
LoggingSystem
.
ROOT_LOGGER_NAME
)
?
null
:
name
;
system
.
setLogLevel
(
name
,
coerceLogLevel
(
level
.
trim
()
));
system
.
setLogLevel
(
name
,
coerceLogLevel
(
level
));
}
}
catch
(
RuntimeException
ex
)
{
catch
(
RuntimeException
ex
)
{
this
.
logger
.
error
(
"Cannot set level
: "
+
level
+
"
for '"
+
name
+
"'"
);
this
.
logger
.
error
(
"Cannot set level
'"
+
level
+
"'
for '"
+
name
+
"'"
);
}
}
}
}
private
LogLevel
coerceLogLevel
(
String
level
)
{
private
LogLevel
coerceLogLevel
(
String
level
)
{
if
(
"false"
.
equalsIgnoreCase
(
level
))
{
String
trimmedLevel
=
level
.
trim
();
if
(
"false"
.
equalsIgnoreCase
(
trimmedLevel
))
{
return
LogLevel
.
OFF
;
return
LogLevel
.
OFF
;
}
}
return
LogLevel
.
valueOf
(
l
evel
.
toUpperCase
(
Locale
.
ENGLISH
));
return
LogLevel
.
valueOf
(
trimmedL
evel
.
toUpperCase
(
Locale
.
ENGLISH
));
}
}
private
void
registerShutdownHookIfNecessary
(
Environment
environment
,
private
void
registerShutdownHookIfNecessary
(
Environment
environment
,
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java
View file @
e1ad5641
...
@@ -318,6 +318,18 @@ public class LoggingApplicationListenerTests {
...
@@ -318,6 +318,18 @@ public class LoggingApplicationListenerTests {
assertThat
(
this
.
outputCapture
.
toString
()).
contains
(
"testattrace"
);
assertThat
(
this
.
outputCapture
.
toString
()).
contains
(
"testattrace"
);
}
}
@Test
public
void
parseLevelsTrimsWhitespace
()
{
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
"logging.level.org.springframework.boot= trace "
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
this
.
logger
.
debug
(
"testatdebug"
);
this
.
logger
.
trace
(
"testattrace"
);
assertThat
(
this
.
outputCapture
.
toString
()).
contains
(
"testatdebug"
);
assertThat
(
this
.
outputCapture
.
toString
()).
contains
(
"testattrace"
);
}
@Test
@Test
public
void
parseLevelsWithPlaceholder
()
{
public
void
parseLevelsWithPlaceholder
()
{
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
TestPropertySourceUtils
.
addInlinedPropertiesToEnvironment
(
this
.
context
,
...
@@ -338,7 +350,7 @@ public class LoggingApplicationListenerTests {
...
@@ -338,7 +350,7 @@ public class LoggingApplicationListenerTests {
this
.
context
.
getClassLoader
());
this
.
context
.
getClassLoader
());
this
.
logger
.
debug
(
"testatdebug"
);
this
.
logger
.
debug
(
"testatdebug"
);
assertThat
(
this
.
outputCapture
.
toString
()).
doesNotContain
(
"testatdebug"
)
assertThat
(
this
.
outputCapture
.
toString
()).
doesNotContain
(
"testatdebug"
)
.
contains
(
"Cannot set level
: GARBAGE
"
);
.
contains
(
"Cannot set level
'GARBAGE'
"
);
}
}
@Test
@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