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
1168d8fa
Commit
1168d8fa
authored
Aug 03, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce reflection in LoggingSystem to make it more Graal-friendly
Closes gh-22594
parent
989fc365
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
12 deletions
+67
-12
LoggingSystem.java
.../java/org/springframework/boot/logging/LoggingSystem.java
+21
-12
LogbackAndLog4J2ExcludedLoggingSystemTests.java
...t/logging/LogbackAndLog4J2ExcludedLoggingSystemTests.java
+40
-0
LoggingSystemTests.java
.../org/springframework/boot/logging/LoggingSystemTests.java
+6
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java
View file @
1168d8fa
...
...
@@ -19,11 +19,13 @@ package org.springframework.boot.logging;
import
java.lang.reflect.Constructor
;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.Function
;
import
org.springframework.boot.logging.java.JavaLoggingSystem
;
import
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
;
import
org.springframework.boot.logging.logback.LogbackLoggingSystem
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -56,15 +58,24 @@ public abstract class LoggingSystem {
*/
public
static
final
String
ROOT_LOGGER_NAME
=
"ROOT"
;
private
static
final
Map
<
String
,
String
>
SYSTEMS
;
private
static
final
Function
<
ClassLoader
,
LoggingSystem
>
SYSTEM_FACTORY
;
static
{
Map
<
String
,
String
>
systems
=
new
LinkedHashMap
<>();
systems
.
put
(
"ch.qos.logback.core.Appender"
,
"org.springframework.boot.logging.logback.LogbackLoggingSystem"
);
systems
.
put
(
"org.apache.logging.log4j.core.impl.Log4jContextFactory"
,
"org.springframework.boot.logging.log4j2.Log4J2LoggingSystem"
);
systems
.
put
(
"java.util.logging.LogManager"
,
"org.springframework.boot.logging.java.JavaLoggingSystem"
);
SYSTEMS
=
Collections
.
unmodifiableMap
(
systems
);
ClassLoader
classLoader
=
LoggingSystem
.
class
.
getClassLoader
();
if
(
ClassUtils
.
isPresent
(
"ch.qos.logback.core.Appender"
,
classLoader
))
{
SYSTEM_FACTORY
=
(
cl
)
->
new
LogbackLoggingSystem
(
cl
);
}
else
if
(
ClassUtils
.
isPresent
(
"org.apache.logging.log4j.core.impl.Log4jContextFactory"
,
classLoader
))
{
SYSTEM_FACTORY
=
(
cl
)
->
new
Log4J2LoggingSystem
(
cl
);
}
else
if
(
ClassUtils
.
isPresent
(
"java.util.logging.LogManager"
,
classLoader
))
{
SYSTEM_FACTORY
=
(
cl
)
->
new
JavaLoggingSystem
(
cl
);
}
else
{
SYSTEM_FACTORY
=
(
cl
)
->
{
throw
new
IllegalStateException
(
"No suitable logging system located"
);
};
}
}
/**
...
...
@@ -155,9 +166,7 @@ public abstract class LoggingSystem {
}
return
get
(
classLoader
,
loggingSystem
);
}
return
SYSTEMS
.
entrySet
().
stream
().
filter
((
entry
)
->
ClassUtils
.
isPresent
(
entry
.
getKey
(),
classLoader
))
.
map
((
entry
)
->
get
(
classLoader
,
entry
.
getValue
())).
findFirst
()
.
orElseThrow
(()
->
new
IllegalStateException
(
"No suitable logging system located"
));
return
SYSTEM_FACTORY
.
apply
(
classLoader
);
}
private
static
LoggingSystem
get
(
ClassLoader
classLoader
,
String
loggingSystemClass
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/LogbackAndLog4J2ExcludedLoggingSystemTests.java
0 → 100644
View file @
1168d8fa
/*
* 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
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.logging.java.JavaLoggingSystem
;
import
org.springframework.boot.testsupport.classpath.ClassPathExclusions
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link LoggingSystem} when Logback is not on the classpath.
*
* @author Andy Wilkinson
*/
// Log4j2 is implicitly excluded due to LOG4J-2030
@ClassPathExclusions
(
"logback-*.jar"
)
class
LogbackAndLog4J2ExcludedLoggingSystemTests
{
@Test
void
whenLogbackAndLog4J2AreNotPresentJULIsTheLoggingSystem
()
{
assertThat
(
LoggingSystem
.
get
(
getClass
().
getClassLoader
())).
isInstanceOf
(
JavaLoggingSystem
.
class
);
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/LoggingSystemTests.java
View file @
1168d8fa
...
...
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.AfterEach;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.logging.LoggingSystem.NoOpLoggingSystem
;
import
org.springframework.boot.logging.logback.LogbackLoggingSystem
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
...
...
@@ -36,6 +37,11 @@ class LoggingSystemTests {
System
.
clearProperty
(
LoggingSystem
.
SYSTEM_PROPERTY
);
}
@Test
void
logbackIsTheDefaultLoggingSystem
()
{
assertThat
(
LoggingSystem
.
get
(
getClass
().
getClassLoader
())).
isInstanceOf
(
LogbackLoggingSystem
.
class
);
}
@Test
void
loggingSystemCanBeDisabled
()
{
System
.
setProperty
(
LoggingSystem
.
SYSTEM_PROPERTY
,
LoggingSystem
.
NONE
);
...
...
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