ppkarwasz commented on code in PR #2374:
URL: https://github.com/apache/logging-log4j2/pull/2374#discussion_r1527192000
##########
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java:
##########
@@ -20,39 +20,135 @@
import java.net.URL;
import java.util.Properties;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.Constants;
+import org.apache.logging.log4j.util.Lazy;
+import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
/**
- * Model class for a Log4j 2 provider. The properties in this class correspond
to the properties used in a
- * {@code META-INF/log4j-provider.properties} file. Note that this class is
automatically created by Log4j and should
- * not be used by providers.
+ * Service class used to bind the Log4j API with an implementation.
+ * <p>
+ * Implementors should register an implementation of this class with
{@link java.util.ServiceLoader}.
+ * </p>
+ * <p>
+ * <strong>Deprecated:</strong> the automatic registration of providers
from
+ * {@code META-INF/log4j-provider.properties} is supported for
compatibility reasons. Support for this file will
+ * be dropped in a future version.
+ * </p>
*/
public class Provider {
+ protected static final String CURRENT_VERSION = "2.6.0";
+
/**
* Property name to set for a Log4j 2 provider to specify the priority of
this implementation.
+ * @deprecated since 2.24.0
*/
+ @Deprecated
public static final String FACTORY_PRIORITY = "FactoryPriority";
+
/**
- * Property name to set to the implementation of {@link
org.apache.logging.log4j.spi.ThreadContextMap}.
+ * Property name to set to the implementation of {@link ThreadContextMap}.
+ * @deprecated since 2.24.0
*/
+ @Deprecated
public static final String THREAD_CONTEXT_MAP = "ThreadContextMap";
+
/**
- * Property name to set to the implementation of {@link
org.apache.logging.log4j.spi.LoggerContextFactory}.
+ * Property name to set to the implementation of {@link
LoggerContextFactory}.
+ * @deprecated since 2.24.0
*/
+ @Deprecated
public static final String LOGGER_CONTEXT_FACTORY = "LoggerContextFactory";
- private static final Integer DEFAULT_PRIORITY = Integer.valueOf(-1);
+ /**
+ * System property used to specify the class name of the provider to use.
+ * @since 2.24.0
+ */
+ public static final String PROVIDER_PROPERTY_NAME = "log4j.provider";
+
+ // Bundled context map implementations
+ private static final String BASE =
"org.apache.logging.log4j.internal.map.";
+
+ /**
+ * Constant used to disable the {@link ThreadContextMap}.
+ * <p>
+ * <strong>Warning:</strong> the value of this constant does not point
to a concrete class name.
+ * </p>
+ * @see #getThreadContextMap
+ */
+ public static final String NO_OP_CONTEXT_MAP = BASE + "NoOp";
+
+ /**
+ * Constant used to select a web application-safe implementation of {@link
ThreadContextMap}.
+ * <p>
+ * This implementation only binds JRE classes to {@link ThreadLocal}
variables.
+ * </p>
+ * <p>
+ * <strong>Warning:</strong> the value of this constant does not point
to a concrete class name.
+ * </p>
+ * @see #getThreadContextMap
+ */
+ public static final String WEB_APP_CONTEXT_MAP = BASE + "WebApp";
+
+ /**
+ * Constant used to select a copy-on-write implementation of {@link
ThreadContextMap}.
+ * <p>
+ * <strong>Warning:</strong> the value of this constant does not point
to a concrete class name.
+ * </p>
+ * @see #getThreadContextMap
+ */
+ public static final String COPY_ON_WRITE_CONTEXT_MAP = BASE +
"CopyOnWrite";
+
+ /**
+ * Constant used to select a garbage-free implementation of {@link
ThreadContextMap}.
+ * <p>
+ * This implementation must ensure that common operations don't create
new object instances. The drawback is
+ * the necessity to bind custom classes to {@link ThreadLocal}
variables.
+ * </p>
+ * <p>
+ * <strong>Warning:</strong> the value of this constant does not point
to a concrete class name.
+ * </p>
+ * @see #getThreadContextMap
+ */
+ public static final String GARBAGE_FREE_CONTEXT_MAP = BASE + "GarbageFree";
Review Comment:
You are right, they could be `protected`.
The reason I introduced these constants is:
- half of these implementations are package-private. An implementation of
`Provider` can not instantiate them, but `Provider` itself can. To use these
context maps an implementation should:
1. implement `#getThreadContextMap` and return one of these special
constants,
2. make a call to `super.createThreadContextMap()` in its
`#createThreadContextMap` implementation.
- I wanted to separate the characteristics of the context map, from the
implementation. So the constant `WebApp` can switch to @jengebr's
implementation under the hood. Probably I should make these constants shorter.
BTW: IMHO the inclusion of `ThreadContextMap` implementations in the
`log4j-api` unnecessarily bloats the artifact. `ThreadContext` is not a
standalone service for users to store thread-dependent data (although I saw
some users use it for this purpose). It must be tightly linked to the `Logger`
implementation. As such, except Log4j Core, no other Log4j API implementation
requires these 3 implementations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org