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
ea85e0d0
Commit
ea85e0d0
authored
Jul 22, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.2.x'
parents
e1dec606
a43cd18a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
+30
-8
Log4J2LoggingSystem.java
...ingframework/boot/logging/log4j2/Log4J2LoggingSystem.java
+17
-7
Log4J2LoggingSystemTests.java
...amework/boot/logging/log4j2/Log4J2LoggingSystemTests.java
+13
-1
No files found.
spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java
View file @
ea85e0d0
...
...
@@ -125,13 +125,13 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
@Override
public
void
beforeInitialize
()
{
super
.
beforeInitialize
();
get
LoggerConfig
(
null
).
addFilter
(
FILTER
);
get
RootLoggerConfig
(
).
addFilter
(
FILTER
);
}
@Override
public
void
initialize
(
LoggingInitializationContext
initializationContext
,
String
configLocation
,
LogFile
logFile
)
{
get
LoggerConfig
(
null
).
removeFilter
(
FILTER
);
get
RootLoggerConfig
(
).
removeFilter
(
FILTER
);
super
.
initialize
(
initializationContext
,
configLocation
,
logFile
);
}
...
...
@@ -183,15 +183,25 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
}
@Override
public
void
setLogLevel
(
String
loggerName
,
LogLevel
level
)
{
getLoggerConfig
(
loggerName
).
setLevel
(
LEVELS
.
get
(
level
));
public
void
setLogLevel
(
String
loggerName
,
LogLevel
logLevel
)
{
Level
level
=
LEVELS
.
get
(
logLevel
);
LoggerConfig
loggerConfig
=
getLoggerConfig
(
loggerName
);
if
(
loggerConfig
==
null
)
{
loggerConfig
=
new
LoggerConfig
(
loggerName
,
level
,
true
);
getLoggerContext
().
getConfiguration
().
addLogger
(
loggerName
,
loggerConfig
);
}
else
{
loggerConfig
.
setLevel
(
level
);
}
getLoggerContext
().
updateLoggers
();
}
private
LoggerConfig
getRootLoggerConfig
()
{
return
getLoggerContext
().
getConfiguration
().
getLoggerConfig
(
""
);
}
private
LoggerConfig
getLoggerConfig
(
String
loggerName
)
{
LoggerConfig
loggerConfig
=
getLoggerContext
().
getConfiguration
()
.
getLoggerConfig
(
loggerName
==
null
?
""
:
loggerName
);
return
loggerConfig
;
return
getLoggerContext
().
getConfiguration
().
getLoggers
().
get
(
loggerName
);
}
private
LoggerContext
getLoggerContext
()
{
...
...
spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java
View file @
ea85e0d0
...
...
@@ -36,12 +36,13 @@ import org.springframework.util.StringUtils;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
arrayContaining
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
core
.
StringContains
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
...
@@ -130,6 +131,17 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
equalTo
(
1
));
}
@Test
public
void
setLevelOfUnconfiguredLoggerDoesNotAffectRootConfiguration
()
throws
Exception
{
this
.
loggingSystem
.
beforeInitialize
();
this
.
loggingSystem
.
initialize
(
null
,
null
,
null
);
LogManager
.
getRootLogger
().
debug
(
"Hello"
);
this
.
loggingSystem
.
setLogLevel
(
"foo.bar.baz"
,
LogLevel
.
DEBUG
);
LogManager
.
getRootLogger
().
debug
(
"Hello"
);
assertThat
(
this
.
output
.
toString
(),
not
(
containsString
(
"Hello"
)));
}
@Test
@Ignore
(
"Fails on Bamboo"
)
public
void
loggingThatUsesJulIsCaptured
()
{
...
...
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