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
ddfadce9
Commit
ddfadce9
authored
Feb 11, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set all documented system properties in LoggingApplicationListener
Closes gh-5073
parent
4cbbd48f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
25 deletions
+77
-25
LoggingApplicationListener.java
...ingframework/boot/logging/LoggingApplicationListener.java
+53
-14
Log4JLoggingSystem.java
...pringframework/boot/logging/log4j/Log4JLoggingSystem.java
+1
-4
Log4J2LoggingSystem.java
...ingframework/boot/logging/log4j2/Log4J2LoggingSystem.java
+0
-3
LogbackLoggingSystem.java
...gframework/boot/logging/logback/LogbackLoggingSystem.java
+0
-3
LoggingApplicationListenerTests.java
...amework/boot/logging/LoggingApplicationListenerTests.java
+23
-1
No files found.
spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java
View file @
ddfadce9
...
...
@@ -109,6 +109,31 @@ public class LoggingApplicationListener implements GenericApplicationListener {
*/
public
static
final
String
EXCEPTION_CONVERSION_WORD
=
"LOG_EXCEPTION_CONVERSION_WORD"
;
/**
* The name of the System property that contains the log file.
*/
public
static
final
String
LOG_FILE
=
"LOG_FILE"
;
/**
* The name of the System property that contains the log file.
*/
public
static
final
String
LOG_PATH
=
"LOG_PATH"
;
/**
* The name of the System property that contains the console log pattern
*/
public
static
final
String
CONSOLE_LOG_PATTERN
=
"CONSOLE_LOG_PATTERN"
;
/**
* The name of the System property that contains the file log pattern
*/
public
static
final
String
FILE_LOG_PATTERN
=
"FILE_LOG_PATTERN"
;
/**
* The name of the System property that contains the log level pattern
*/
public
static
final
String
LOG_LEVEL_PATTERN
=
"LOG_LEVEL_PATTERN"
;
/**
* The name of the {@link LoggingSystem} bean.
*/
...
...
@@ -222,23 +247,38 @@ public class LoggingApplicationListener implements GenericApplicationListener {
*/
protected
void
initialize
(
ConfigurableEnvironment
environment
,
ClassLoader
classLoader
)
{
if
(
System
.
getProperty
(
PID_KEY
)
==
null
)
{
System
.
setProperty
(
PID_KEY
,
new
ApplicationPid
().
toString
());
}
if
(
System
.
getProperty
(
EXCEPTION_CONVERSION_WORD
)
==
null
)
{
System
.
setProperty
(
EXCEPTION_CONVERSION_WORD
,
getExceptionConversionWord
(
environment
));
}
LogFile
logFile
=
LogFile
.
get
(
environment
);
setSystemProperties
(
environment
,
logFile
);
initializeEarlyLoggingLevel
(
environment
);
initializeSystem
(
environment
,
this
.
loggingSystem
);
initializeSystem
(
environment
,
this
.
loggingSystem
,
logFile
);
initializeFinalLoggingLevels
(
environment
,
this
.
loggingSystem
);
registerShutdownHookIfNecessary
(
environment
,
this
.
loggingSystem
);
}
private
String
getExceptionConversionWord
(
ConfigurableEnvironment
environment
)
{
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
environment
,
"logging."
);
return
resolver
.
getProperty
(
"exception-conversion-word"
,
"%wEx"
);
private
void
setSystemProperties
(
ConfigurableEnvironment
environment
,
LogFile
logFile
)
{
RelaxedPropertyResolver
propertyResolver
=
new
RelaxedPropertyResolver
(
environment
,
"logging."
);
setSystemProperty
(
propertyResolver
,
EXCEPTION_CONVERSION_WORD
,
"exception-conversion-word"
);
setSystemProperty
(
propertyResolver
,
CONSOLE_LOG_PATTERN
,
"pattern.console"
);
setSystemProperty
(
propertyResolver
,
FILE_LOG_PATTERN
,
"pattern.file"
);
setSystemProperty
(
propertyResolver
,
LOG_LEVEL_PATTERN
,
"pattern.level"
);
setSystemProperty
(
PID_KEY
,
new
ApplicationPid
().
toString
());
if
(
logFile
!=
null
)
{
logFile
.
applyToSystemProperties
();
}
}
private
void
setSystemProperty
(
RelaxedPropertyResolver
propertyResolver
,
String
systemPropertyName
,
String
propertyName
)
{
setSystemProperty
(
systemPropertyName
,
propertyResolver
.
getProperty
(
propertyName
));
}
private
void
setSystemProperty
(
String
name
,
String
value
)
{
if
(
System
.
getProperty
(
name
)
==
null
&&
value
!=
null
)
{
System
.
setProperty
(
name
,
value
);
}
}
private
void
initializeEarlyLoggingLevel
(
ConfigurableEnvironment
environment
)
{
...
...
@@ -253,10 +293,9 @@ public class LoggingApplicationListener implements GenericApplicationListener {
}
private
void
initializeSystem
(
ConfigurableEnvironment
environment
,
LoggingSystem
system
)
{
LoggingSystem
system
,
LogFile
logFile
)
{
LoggingInitializationContext
initializationContext
=
new
LoggingInitializationContext
(
environment
);
LogFile
logFile
=
LogFile
.
get
(
environment
);
String
logConfig
=
environment
.
getProperty
(
CONFIG_PROPERTY
);
if
(
ignoreLogConfig
(
logConfig
))
{
system
.
initialize
(
initializationContext
,
null
,
logFile
);
...
...
spring-boot/src/main/java/org/springframework/boot/logging/log4j/Log4JLoggingSystem.java
View file @
ddfadce9
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
...
@@ -93,9 +93,6 @@ public class Log4JLoggingSystem extends Slf4JLoggingSystem {
protected
void
loadConfiguration
(
String
location
,
LogFile
logFile
)
{
Assert
.
notNull
(
location
,
"Location must not be null"
);
if
(
logFile
!=
null
)
{
logFile
.
applyToSystemProperties
();
}
try
{
Log4jConfigurer
.
initLogging
(
location
);
}
...
...
spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java
View file @
ddfadce9
...
...
@@ -157,9 +157,6 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
protected
void
loadConfiguration
(
String
location
,
LogFile
logFile
)
{
Assert
.
notNull
(
location
,
"Location must not be null"
);
if
(
logFile
!=
null
)
{
logFile
.
applyToSystemProperties
();
}
try
{
LoggerContext
ctx
=
getLoggerContext
();
URL
url
=
ResourceUtils
.
getURL
(
location
);
...
...
spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java
View file @
ddfadce9
...
...
@@ -128,9 +128,6 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
protected
void
loadConfiguration
(
LoggingInitializationContext
initializationContext
,
String
location
,
LogFile
logFile
)
{
Assert
.
notNull
(
location
,
"Location must not be null"
);
if
(
logFile
!=
null
)
{
logFile
.
applyToSystemProperties
();
}
LoggerContext
loggerContext
=
getLoggerContext
();
stopAndReset
(
loggerContext
);
try
{
...
...
spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java
View file @
ddfadce9
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
...
@@ -45,6 +45,7 @@ import org.springframework.context.support.GenericApplicationContext;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
...
...
@@ -98,6 +99,9 @@ public class LoggingApplicationListenerTests {
System
.
clearProperty
(
"LOG_PATH"
);
System
.
clearProperty
(
"PID"
);
System
.
clearProperty
(
"LOG_EXCEPTION_CONVERSION_WORD"
);
System
.
clearProperty
(
"CONSOLE_LOG_PATTERN"
);
System
.
clearProperty
(
"FILE_LOG_PATTERN"
);
System
.
clearProperty
(
"LOG_LEVEL_PATTERN"
);
System
.
clearProperty
(
LoggingSystem
.
SYSTEM_PROPERTY
);
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
...
...
@@ -419,6 +423,24 @@ public class LoggingApplicationListenerTests {
childContext
.
close
();
}
@Test
public
void
systemPropertiesAreSetForLoggingConfiguration
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"logging.exception-conversion-word=conversion"
,
"logging.file=file"
,
"logging.path=path"
,
"logging.pattern.console=console"
,
"logging.pattern.file=file"
,
"logging.pattern.level=level"
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
assertThat
(
System
.
getProperty
(
"CONSOLE_LOG_PATTERN"
),
is
(
equalTo
(
"console"
)));
assertThat
(
System
.
getProperty
(
"FILE_LOG_PATTERN"
),
is
(
equalTo
(
"file"
)));
assertThat
(
System
.
getProperty
(
"LOG_EXCEPTION_CONVERSION_WORD"
),
is
(
equalTo
(
"conversion"
)));
assertThat
(
System
.
getProperty
(
"LOG_FILE"
),
is
(
equalTo
(
"file"
)));
assertThat
(
System
.
getProperty
(
"LOG_LEVEL_PATTERN"
),
is
(
equalTo
(
"level"
)));
assertThat
(
System
.
getProperty
(
"LOG_PATH"
),
is
(
equalTo
(
"path"
)));
assertThat
(
System
.
getProperty
(
"PID"
),
is
(
not
(
nullValue
())));
}
private
boolean
bridgeHandlerInstalled
()
{
Logger
rootLogger
=
LogManager
.
getLogManager
().
getLogger
(
""
);
Handler
[]
handlers
=
rootLogger
.
getHandlers
();
...
...
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