You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/08 19:58:20 UTC
[logging-log4j2] 01/03: Only check if log4j-core is available once.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit c61ec4abeee445b7448dfc8bc670ceebab575aee
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 8 14:48:42 2022 -0500
Only check if log4j-core is available once.
---
.../src/main/java/org/apache/log4j/spi/Filter.java | 25 +++++++++++++++-------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/Filter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/Filter.java
index 997398b..5cd7189 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/Filter.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/Filter.java
@@ -22,17 +22,24 @@ import org.apache.log4j.bridge.FilterAdapter;
* @since 0.9.0
*/
public abstract class Filter {
- private final FilterAdapter adapter;
- public Filter() {
- FilterAdapter filterAdapter = null;
+ static {
+ boolean temp;
try {
- Class.forName("org.apache.logging.log4j.core.Filter");
- filterAdapter = new FilterAdapter(this);
- } catch(ClassNotFoundException ex) {
- // Ignore the exception. Log4j Core is not present.
+ temp = Class.forName("org.apache.logging.log4j.core.Filter") != null;
+ } catch (Exception e) {
+ temp = false;
}
- this.adapter = filterAdapter;
+ isCorePresent = temp;
+ }
+
+ private final FilterAdapter adapter;
+
+ /**
+ * C
+ */
+ public Filter() {
+ this.adapter = isCorePresent ? new FilterAdapter(this) : null;
}
/**
@@ -61,6 +68,8 @@ public abstract class Filter {
@Deprecated
public Filter next;
+ private static final boolean isCorePresent;
+
/**
* Usually filters options become active when set. We provide a
* default do-nothing implementation for convenience.