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
daf2b2fe
Commit
daf2b2fe
authored
Jan 15, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Fixes gh-24846
parents
b7843f93
c0aef4c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
13 deletions
+48
-13
LoggingSystemProperties.java
...springframework/boot/logging/LoggingSystemProperties.java
+23
-4
LogbackLoggingSystem.java
...gframework/boot/logging/logback/LogbackLoggingSystem.java
+4
-8
LogbackLoggingSystemTests.java
...ework/boot/logging/logback/LogbackLoggingSystemTests.java
+21
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystemProperties.java
View file @
daf2b2fe
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.logging;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.function.BiConsumer
;
import
org.springframework.boot.system.ApplicationPid
;
import
org.springframework.core.env.ConfigurableEnvironment
;
...
...
@@ -130,15 +131,35 @@ public class LoggingSystemProperties {
*/
public
static
final
String
LOG_DATEFORMAT_PATTERN
=
"LOG_DATEFORMAT_PATTERN"
;
private
static
final
BiConsumer
<
String
,
String
>
systemPropertySetter
=
(
name
,
value
)
->
{
if
(
System
.
getProperty
(
name
)
==
null
&&
value
!=
null
)
{
System
.
setProperty
(
name
,
value
);
}
};
private
final
Environment
environment
;
private
final
BiConsumer
<
String
,
String
>
setter
;
/**
* Create a new {@link LoggingSystemProperties} instance.
* @param environment the source environment
*/
public
LoggingSystemProperties
(
Environment
environment
)
{
this
(
environment
,
systemPropertySetter
);
}
/**
* Create a new {@link LoggingSystemProperties} instance.
* @param environment the source environment
* @param setter setter used to apply the property
* @since 2.4.2
*/
public
LoggingSystemProperties
(
Environment
environment
,
BiConsumer
<
String
,
String
>
setter
)
{
Assert
.
notNull
(
environment
,
"Environment must not be null"
);
Assert
.
notNull
(
setter
,
"Setter must not be null"
);
this
.
environment
=
environment
;
this
.
setter
=
setter
;
}
protected
Charset
getDefaultCharset
()
{
...
...
@@ -200,9 +221,7 @@ public class LoggingSystemProperties {
}
protected
final
void
setSystemProperty
(
String
name
,
String
value
)
{
if
(
System
.
getProperty
(
name
)
==
null
&&
value
!=
null
)
{
System
.
setProperty
(
name
,
value
);
}
this
.
setter
.
accept
(
name
,
value
);
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java
View file @
daf2b2fe
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -146,15 +146,11 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
if
(
debug
)
{
StatusListenerConfigHelper
.
addOnConsoleListenerInstance
(
context
,
new
OnConsoleStatusListener
());
}
Environment
environment
=
initializationContext
.
getEnvironment
();
// Apply system properties directly in case the same JVM runs multiple apps
new
LoggingSystemProperties
(
environment
,
context:
:
putProperty
).
apply
(
logFile
);
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}}"
));
context
.
putProperty
(
LoggingSystemProperties
.
LOG_DATEFORMAT_PATTERN
,
environment
.
resolvePlaceholders
(
"${logging.pattern.dateformat:${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}"
));
context
.
putProperty
(
LoggingSystemProperties
.
ROLLING_FILE_NAME_PATTERN
,
environment
.
resolvePlaceholders
(
"${logging.pattern.rolling-file-name:${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}"
));
new
DefaultLogbackConfiguration
(
initializationContext
,
logFile
).
apply
(
configurator
);
context
.
setPackagingDataEnabled
(
true
);
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java
View file @
daf2b2fe
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -20,7 +20,9 @@ import java.io.File;
import
java.nio.charset.StandardCharsets
;
import
java.util.Arrays
;
import
java.util.EnumSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.logging.Handler
;
import
java.util.logging.LogManager
;
...
...
@@ -87,10 +89,13 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
private
LoggingInitializationContext
initializationContext
;
private
Set
<
Object
>
systemPropertyNames
;
@BeforeEach
void
setup
()
{
System
.
getProperties
().
remove
(
LoggingSystemProperties
.
CONSOLE_LOG_CHARSET
);
System
.
getProperties
().
remove
(
LoggingSystemProperties
.
FILE_LOG_CHARSET
);
this
.
systemPropertyNames
=
new
HashSet
<>(
System
.
getProperties
().
keySet
());
this
.
loggingSystem
.
cleanUp
();
this
.
logger
=
((
LoggerContext
)
StaticLoggerBinder
.
getSingleton
().
getLoggerFactory
()).
getLogger
(
getClass
());
this
.
environment
=
new
MockEnvironment
();
...
...
@@ -101,6 +106,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
@AfterEach
void
cleanUp
()
{
System
.
getProperties
().
keySet
().
retainAll
(
this
.
systemPropertyNames
);
this
.
loggingSystem
.
cleanUp
();
((
LoggerContext
)
StaticLoggerBinder
.
getSingleton
().
getLoggerFactory
()).
stop
();
}
...
...
@@ -312,6 +318,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
@Test
void
testLevelPatternProperty
(
CapturedOutput
output
)
{
this
.
environment
.
setProperty
(
"logging.pattern.level"
,
"X%clr(%p)X"
);
new
LoggingSystemProperties
(
this
.
environment
).
apply
();
LoggingInitializationContext
loggingInitializationContext
=
new
LoggingInitializationContext
(
this
.
environment
);
initialize
(
loggingInitializationContext
,
null
,
null
);
this
.
logger
.
info
(
"Hello world"
);
...
...
@@ -513,6 +520,19 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
@Test
void
testDateformatPatternProperty
(
CapturedOutput
output
)
{
this
.
environment
.
setProperty
(
"logging.pattern.dateformat"
,
"yyyy-MM-dd'T'hh:mm:ss.SSSZ"
);
new
LoggingSystemProperties
(
this
.
environment
).
apply
();
LoggingInitializationContext
loggingInitializationContext
=
new
LoggingInitializationContext
(
this
.
environment
);
initialize
(
loggingInitializationContext
,
null
,
null
);
this
.
logger
.
info
(
"Hello world"
);
assertThat
(
getLineWithText
(
output
,
"Hello world"
))
.
containsPattern
(
"\\d{4}-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2}"
);
}
@Test
// gh-24835
void
testDateformatPatternPropertyDirect
(
CapturedOutput
output
)
{
this
.
environment
.
setProperty
(
"logging.pattern.dateformat"
,
"yyyy'T'hh:mm:ss.SSSZ"
);
new
LoggingSystemProperties
(
this
.
environment
).
apply
();
this
.
environment
.
setProperty
(
"logging.pattern.dateformat"
,
"yyyy-MM-dd'T'hh:mm:ss.SSSZ"
);
LoggingInitializationContext
loggingInitializationContext
=
new
LoggingInitializationContext
(
this
.
environment
);
initialize
(
loggingInitializationContext
,
null
,
null
);
...
...
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