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
75da4468
Commit
75da4468
authored
Jun 14, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-17192
parents
0208cb10
d5d96dff
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
3 deletions
+110
-3
DebugLogbackConfigurator.java
...mework/boot/logging/logback/DebugLogbackConfigurator.java
+72
-0
LogbackConfigurator.java
...ngframework/boot/logging/logback/LogbackConfigurator.java
+1
-2
LogbackLoggingSystem.java
...gframework/boot/logging/logback/LogbackLoggingSystem.java
+8
-1
LogbackLoggingSystemTests.java
...ework/boot/logging/logback/LogbackLoggingSystemTests.java
+29
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/DebugLogbackConfigurator.java
0 → 100644
View file @
75da4468
/*
* Copyright 2012-2019 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
*
* https://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
.
logback
;
import
ch.qos.logback.classic.Level
;
import
ch.qos.logback.classic.LoggerContext
;
import
ch.qos.logback.classic.spi.ILoggingEvent
;
import
ch.qos.logback.core.Appender
;
import
ch.qos.logback.core.pattern.Converter
;
import
ch.qos.logback.core.spi.LifeCycle
;
import
ch.qos.logback.core.status.InfoStatus
;
import
ch.qos.logback.core.status.Status
;
/**
* Custom {@link LogbackConfigurator} used to add {@link Status Statuses} when Logback
* debugging is enabled.
*
* @author Andy Wilkinson
*/
class
DebugLogbackConfigurator
extends
LogbackConfigurator
{
DebugLogbackConfigurator
(
LoggerContext
context
)
{
super
(
context
);
}
@Override
@SuppressWarnings
(
"rawtypes"
)
public
void
conversionRule
(
String
conversionWord
,
Class
<?
extends
Converter
>
converterClass
)
{
info
(
"Adding conversion rule of type '"
+
converterClass
.
getName
()
+
"' for word '"
+
conversionWord
);
super
.
conversionRule
(
conversionWord
,
converterClass
);
}
@Override
public
void
appender
(
String
name
,
Appender
<?>
appender
)
{
info
(
"Adding appender '"
+
appender
+
"' named '"
+
name
+
"'"
);
super
.
appender
(
name
,
appender
);
}
@Override
public
void
logger
(
String
name
,
Level
level
,
boolean
additive
,
Appender
<
ILoggingEvent
>
appender
)
{
info
(
"Configuring logger '"
+
name
+
"' with level '"
+
level
+
"'. Additive: "
+
additive
);
if
(
appender
!=
null
)
{
info
(
"Adding appender '"
+
appender
+
"' to logger '"
+
name
+
"'"
);
}
super
.
logger
(
name
,
level
,
additive
,
appender
);
}
@Override
public
void
start
(
LifeCycle
lifeCycle
)
{
info
(
"Starting '"
+
lifeCycle
+
"'"
);
super
.
start
(
lifeCycle
);
}
private
void
info
(
String
message
)
{
getContext
().
getStatusManager
().
add
(
new
InfoStatus
(
message
,
this
));
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackConfigurator.java
View file @
75da4468
...
...
@@ -28,7 +28,6 @@ import ch.qos.logback.core.CoreConstants;
import
ch.qos.logback.core.pattern.Converter
;
import
ch.qos.logback.core.spi.ContextAware
;
import
ch.qos.logback.core.spi.LifeCycle
;
import
ch.qos.logback.core.spi.PropertyContainer
;
import
org.springframework.util.Assert
;
...
...
@@ -47,7 +46,7 @@ class LogbackConfigurator {
this
.
context
=
context
;
}
public
PropertyContainer
getContext
()
{
public
LoggerContext
getContext
()
{
return
this
.
context
;
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java
View file @
75da4468
...
...
@@ -33,7 +33,9 @@ import ch.qos.logback.classic.turbo.TurboFilter;
import
ch.qos.logback.classic.util.ContextInitializer
;
import
ch.qos.logback.core.joran.spi.JoranException
;
import
ch.qos.logback.core.spi.FilterReply
;
import
ch.qos.logback.core.status.OnConsoleStatusListener
;
import
ch.qos.logback.core.status.Status
;
import
ch.qos.logback.core.util.StatusListenerConfigHelper
;
import
org.slf4j.ILoggerFactory
;
import
org.slf4j.Logger
;
import
org.slf4j.Marker
;
...
...
@@ -125,7 +127,12 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
protected
void
loadDefaults
(
LoggingInitializationContext
initializationContext
,
LogFile
logFile
)
{
LoggerContext
context
=
getLoggerContext
();
stopAndReset
(
context
);
LogbackConfigurator
configurator
=
new
LogbackConfigurator
(
context
);
boolean
debug
=
Boolean
.
getBoolean
(
"logback.debug"
);
if
(
debug
)
{
StatusListenerConfigHelper
.
addOnConsoleListenerInstance
(
context
,
new
OnConsoleStatusListener
());
}
LogbackConfigurator
configurator
=
debug
?
new
DebugLogbackConfigurator
(
context
)
:
new
LogbackConfigurator
(
context
);
Environment
environment
=
initializationContext
.
getEnvironment
();
context
.
putProperty
(
LoggingSystemProperties
.
LOG_LEVEL_PATTERN
,
environment
.
resolvePlaceholders
(
"${logging.pattern.level:${LOG_LEVEL_PATTERN:%5p}}"
));
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java
View file @
75da4468
...
...
@@ -538,6 +538,35 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
.
containsPattern
(
"\\d{4}-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2}"
);
}
@Test
public
void
noDebugOutputIsProducedByDefault
()
{
System
.
clearProperty
(
"logback.debug"
);
this
.
loggingSystem
.
beforeInitialize
();
File
file
=
new
File
(
tmpDir
(),
"logback-test.log"
);
LogFile
logFile
=
getLogFile
(
file
.
getPath
(),
null
);
this
.
loggingSystem
.
initialize
(
this
.
initializationContext
,
null
,
logFile
);
String
output
=
this
.
output
.
toString
().
trim
();
System
.
out
.
println
(
output
);
assertThat
(
output
).
doesNotContain
(
"LevelChangePropagator"
).
doesNotContain
(
"SizeAndTimeBasedFNATP"
);
}
@Test
public
void
logbackDebugPropertyIsHonored
()
{
System
.
setProperty
(
"logback.debug"
,
"true"
);
try
{
this
.
loggingSystem
.
beforeInitialize
();
File
file
=
new
File
(
tmpDir
(),
"logback-test.log"
);
LogFile
logFile
=
getLogFile
(
file
.
getPath
(),
null
);
this
.
loggingSystem
.
initialize
(
this
.
initializationContext
,
null
,
logFile
);
String
output
=
this
.
output
.
toString
().
trim
();
assertThat
(
output
).
contains
(
"LevelChangePropagator"
).
contains
(
"SizeAndTimeBasedFNATP"
)
.
contains
(
"DebugLogbackConfigurator"
);
}
finally
{
System
.
clearProperty
(
"logback.debug"
);
}
}
private
static
Logger
getRootLogger
()
{
ILoggerFactory
factory
=
StaticLoggerBinder
.
getSingleton
().
getLoggerFactory
();
LoggerContext
context
=
(
LoggerContext
)
factory
;
...
...
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