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/05 23:21:44 UTC
[logging-log4j2] 01/02: Log4j 1.2 bridge class Category is missing some protected instance variables.
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 bc0abcdef7c6a2a990cc5f0a896954c2f84b942b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 5 18:21:29 2022 -0500
Log4j 1.2 bridge class Category is missing some protected instance
variables.
---
.../src/main/java/org/apache/log4j/Category.java | 60 ++++++++++++++++++----
1 file changed, 51 insertions(+), 9 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
index be25086..74e62d2 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
@@ -55,9 +55,7 @@ public class Category implements AppenderAttachable {
private static final String FQCN = Category.class.getName();
private static final boolean isCoreAvailable;
-
- private final RendererMap rendererMap;
-
+
static {
boolean available;
@@ -70,9 +68,35 @@ public class Category implements AppenderAttachable {
}
/**
+ * The name of this category.
+ */
+ protected String name;
+
+ /**
+ * Additivity is set to true by default, that is children inherit the appenders of their ancestors by default. If this
+ * variable is set to <code>false</code> then the appenders found in the ancestors of this category are not used.
+ * However, the children of this category will inherit its appenders, unless the children have their additivity flag set
+ * to <code>false</code> too. See the user manual for more details.
+ */
+ protected boolean additive = true;
+
+ /**
+ * The assigned level of this category. The <code>level</code> variable need not be assigned a value in which case it is
+ * inherited form the hierarchy.
+ */
+ volatile protected Level level;
+
+ private final RendererMap rendererMap;
+
+ /**
+ * The parent of this category. All categories have at least one ancestor which is the root category.
+ */
+ volatile protected Category parent;
+
+ /**
* Resource bundle for localized messages.
*/
- protected ResourceBundle bundle = null;
+ protected ResourceBundle bundle;
private final org.apache.logging.log4j.Logger logger;
@@ -85,9 +109,10 @@ public class Category implements AppenderAttachable {
* @param name The name of the Logger.
*/
protected Category(final LoggerContext context, final String name) {
- logger = context.getLogger(name);
- repository = LogManager.getLoggerRepository();
- rendererMap = ((RendererSupport) repository).getRendererMap();
+ this.name = name;
+ this.logger = context.getLogger(name);
+ this.repository = LogManager.getLoggerRepository();
+ this.rendererMap = ((RendererSupport) repository).getRendererMap();
}
/**
@@ -159,8 +184,8 @@ public class Category implements AppenderAttachable {
return null;
}
final ConcurrentMap<String, Logger> loggers = getLoggersMap(loggerContext);
- final Logger l = loggers.get(parent.getName());
- return l == null ? new Category(parent) : l;
+ final Logger parentLogger = loggers.get(parent.getName());
+ return parentLogger == null ? new Category(parent) : parentLogger;
}
public static Category getRoot() {
@@ -377,6 +402,23 @@ public class Category implements AppenderAttachable {
public void callAppenders(final LoggingEvent event) {
}
+ /**
+ * Closes all attached appenders implementing the AppenderAttachable interface.
+ *
+ * @since 1.0
+ */
+ synchronized void closeNestedAppenders() {
+ Enumeration enumeration = this.getAllAppenders();
+ if (enumeration != null) {
+ while (enumeration.hasMoreElements()) {
+ Appender a = (Appender) enumeration.nextElement();
+ if (a instanceof AppenderAttachable) {
+ a.close();
+ }
+ }
+ }
+ }
+
@Override
@SuppressWarnings("rawtypes")
public Enumeration getAllAppenders() {