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
07313d12
Commit
07313d12
authored
Mar 28, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
d66ff0e4
0a7a283f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
125 additions
and
35 deletions
+125
-35
AbstractLoggingSystem.java
...g/springframework/boot/logging/AbstractLoggingSystem.java
+6
-1
LoggingApplicationListener.java
...ingframework/boot/logging/LoggingApplicationListener.java
+6
-29
LoggingSytemProperties.java
.../springframework/boot/logging/LoggingSytemProperties.java
+76
-0
Slf4JLoggingSystem.java
.../org/springframework/boot/logging/Slf4JLoggingSystem.java
+11
-1
Log4J2LoggingSystem.java
...ingframework/boot/logging/log4j2/Log4J2LoggingSystem.java
+1
-0
LogbackLoggingSystem.java
...gframework/boot/logging/logback/LogbackLoggingSystem.java
+1
-1
AbstractLoggingSystemTests.java
...ingframework/boot/logging/AbstractLoggingSystemTests.java
+8
-1
LogbackLoggingSystemTests.java
...ework/boot/logging/logback/LogbackLoggingSystemTests.java
+16
-2
No files found.
spring-boot/src/main/java/org/springframework/boot/logging/AbstractLoggingSystem.java
View file @
07313d12
/*
* 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.
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
logging
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -168,4 +169,8 @@ public abstract class AbstractLoggingSystem extends LoggingSystem {
return
defaultPath
;
}
protected
final
void
applySystemProperties
(
Environment
environment
,
LogFile
logFile
)
{
new
LoggingSytemProperties
(
environment
).
apply
(
logFile
);
}
}
spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java
View file @
07313d12
...
...
@@ -25,7 +25,6 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.boot.ApplicationPid
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
...
...
@@ -103,12 +102,12 @@ public class LoggingApplicationListener implements GenericApplicationListener {
/**
* The name of the System property that contains the process ID.
*/
public
static
final
String
PID_KEY
=
"PID"
;
public
static
final
String
PID_KEY
=
LoggingSytemProperties
.
PID_KEY
;
/**
* The name of the System property that contains the exception conversion word.
*/
public
static
final
String
EXCEPTION_CONVERSION_WORD
=
"LOG_EXCEPTION_CONVERSION_WORD"
;
public
static
final
String
EXCEPTION_CONVERSION_WORD
=
LoggingSytemProperties
.
EXCEPTION_CONVERSION_WORD
;
/**
* The name of the System property that contains the log file.
...
...
@@ -123,17 +122,17 @@ public class LoggingApplicationListener implements GenericApplicationListener {
/**
* The name of the System property that contains the console log pattern.
*/
public
static
final
String
CONSOLE_LOG_PATTERN
=
"CONSOLE_LOG_PATTERN"
;
public
static
final
String
CONSOLE_LOG_PATTERN
=
LoggingSytemProperties
.
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"
;
public
static
final
String
FILE_LOG_PATTERN
=
LoggingSytemProperties
.
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"
;
public
static
final
String
LOG_LEVEL_PATTERN
=
LoggingSytemProperties
.
LOG_LEVEL_PATTERN
;
/**
* The name of the {@link LoggingSystem} bean.
...
...
@@ -248,7 +247,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
*/
protected
void
initialize
(
ConfigurableEnvironment
environment
,
ClassLoader
classLoader
)
{
setSystemProperties
(
environment
);
new
LoggingSytemProperties
(
environment
).
apply
(
);
LogFile
logFile
=
LogFile
.
get
(
environment
);
if
(
logFile
!=
null
)
{
logFile
.
applyToSystemProperties
();
...
...
@@ -259,28 +258,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
registerShutdownHookIfNecessary
(
environment
,
this
.
loggingSystem
);
}
private
void
setSystemProperties
(
ConfigurableEnvironment
environment
)
{
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
());
}
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
)
{
if
(
this
.
parseArgs
&&
this
.
springBootLogging
==
null
)
{
if
(
isSet
(
environment
,
"debug"
))
{
...
...
spring-boot/src/main/java/org/springframework/boot/logging/LoggingSytemProperties.java
0 → 100644
View file @
07313d12
/*
* Copyright 2012-2016 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
*
* http://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
;
import
org.springframework.boot.ApplicationPid
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.core.env.Environment
;
/**
* Utility to set system properties that can later be used by log configuration files.
*
* @author Andy Wilkinson
* @author Phillip Webb
*/
class
LoggingSytemProperties
{
static
final
String
PID_KEY
=
"PID"
;
static
final
String
EXCEPTION_CONVERSION_WORD
=
"LOG_EXCEPTION_CONVERSION_WORD"
;
static
final
String
CONSOLE_LOG_PATTERN
=
"CONSOLE_LOG_PATTERN"
;
static
final
String
FILE_LOG_PATTERN
=
"FILE_LOG_PATTERN"
;
static
final
String
LOG_LEVEL_PATTERN
=
"LOG_LEVEL_PATTERN"
;
private
final
Environment
environment
;
LoggingSytemProperties
(
Environment
environment
)
{
this
.
environment
=
environment
;
}
public
void
apply
()
{
apply
(
null
);
}
public
void
apply
(
LogFile
logFile
)
{
RelaxedPropertyResolver
propertyResolver
=
new
RelaxedPropertyResolver
(
this
.
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
);
}
}
}
spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java
View file @
07313d12
/*
* 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.
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.logging;
import
org.slf4j.bridge.SLF4JBridgeHandler
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
/**
...
...
@@ -45,6 +46,15 @@ public abstract class Slf4JLoggingSystem extends AbstractLoggingSystem {
removeJdkLoggingBridgeHandler
();
}
@Override
protected
void
loadConfiguration
(
LoggingInitializationContext
initializationContext
,
String
location
,
LogFile
logFile
)
{
Assert
.
notNull
(
location
,
"Location must not be null"
);
if
(
initializationContext
!=
null
)
{
applySystemProperties
(
initializationContext
.
getEnvironment
(),
logFile
);
}
}
private
void
configureJdkLoggingBridgeHandler
()
{
try
{
if
(
isBridgeHandlerAvailable
())
{
...
...
spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java
View file @
07313d12
...
...
@@ -152,6 +152,7 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
@Override
protected
void
loadConfiguration
(
LoggingInitializationContext
initializationContext
,
String
location
,
LogFile
logFile
)
{
super
.
loadConfiguration
(
initializationContext
,
location
,
logFile
);
loadConfiguration
(
location
,
logFile
);
}
...
...
spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java
View file @
07313d12
...
...
@@ -128,7 +128,7 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
@Override
protected
void
loadConfiguration
(
LoggingInitializationContext
initializationContext
,
String
location
,
LogFile
logFile
)
{
Assert
.
notNull
(
location
,
"Location must not be null"
);
super
.
loadConfiguration
(
initializationContext
,
location
,
logFile
);
LoggerContext
loggerContext
=
getLoggerContext
();
stopAndReset
(
loggerContext
);
try
{
...
...
spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java
View file @
07313d12
...
...
@@ -62,8 +62,15 @@ public abstract class AbstractLoggingSystemTests {
}
protected
final
LogFile
getLogFile
(
String
file
,
String
path
)
{
return
getLogFile
(
file
,
path
,
true
);
}
protected
final
LogFile
getLogFile
(
String
file
,
String
path
,
boolean
applyToSystemProperties
)
{
LogFile
logFile
=
new
LogFile
(
file
,
path
);
logFile
.
applyToSystemProperties
();
if
(
applyToSystemProperties
)
{
logFile
.
applyToSystemProperties
();
}
return
logFile
;
}
...
...
spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java
View file @
07313d12
...
...
@@ -68,11 +68,13 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
private
LoggingInitializationContext
initializationContext
;
private
MockEnvironment
environment
;
@Before
public
void
setup
()
{
this
.
logger
=
new
SLF4JLogFactory
().
getInstance
(
getClass
().
getName
());
this
.
initializationContext
=
new
LoggingInitializationContext
(
new
MockEnvironment
()
);
this
.
environment
=
new
MockEnvironment
();
this
.
initializationContext
=
new
LoggingInitializationContext
(
this
.
environment
);
}
@Override
...
...
@@ -301,6 +303,18 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
}
}
@Test
public
void
reinitializeShouldSetSytemProperty
()
throws
Exception
{
// gh-5491
this
.
loggingSystem
.
beforeInitialize
();
this
.
logger
.
info
(
"Hidden"
);
this
.
loggingSystem
.
initialize
(
this
.
initializationContext
,
null
,
null
);
LogFile
logFile
=
getLogFile
(
tmpDir
()
+
"/example.log"
,
null
,
false
);
this
.
loggingSystem
.
initialize
(
this
.
initializationContext
,
"classpath:logback-nondefault.xml"
,
logFile
);
assertThat
(
System
.
getProperty
(
"LOG_FILE"
)).
endsWith
(
"example.log"
);
}
private
String
getLineWithText
(
File
file
,
String
outputSearch
)
throws
Exception
{
return
getLineWithText
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
)),
outputSearch
);
...
...
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