This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new 8da9147153 Move log4j-api property names to LoggingSystemProperties
8da9147153 is described below
commit 8da91471537f8a5918c7bb652155aa85a5f76ed7
Author: Matt Sicker <[email protected]>
AuthorDate: Sat Nov 12 17:17:48 2022 -0600
Move log4j-api property names to LoggingSystemProperties
This centralizes all the current properties referenced in log4j-api for
consistency and documentation.
Signed-off-by: Matt Sicker <[email protected]>
---
.../logging/log4j/NoopThreadContextTest.java | 5 +-
.../log4j/ThreadContextInheritanceTest.java | 6 +-
.../org/apache/logging/log4j/util/Unbox1Test.java | 4 +-
.../java/org/apache/logging/log4j/LogManager.java | 3 +-
.../org/apache/logging/log4j/ThreadContext.java | 3 +-
.../log4j/message/MapMessageJsonFormatter.java | 7 +-
.../apache/logging/log4j/spi/AbstractLogger.java | 4 +-
.../CopyOnWriteSortedArrayThreadContextMap.java | 5 +-
.../logging/log4j/spi/DefaultThreadContextMap.java | 6 +-
.../GarbageFreeSortedArrayThreadContextMap.java | 5 +-
.../apache/logging/log4j/spi/LoggingSystem.java | 21 +--
.../logging/log4j/spi/LoggingSystemProperties.java | 173 +++++++++++++++++++++
.../logging/log4j/spi/NoOpThreadContextMap.java | 5 +-
.../apache/logging/log4j/status/StatusLogger.java | 12 +-
.../org/apache/logging/log4j/util/Constants.java | 21 +--
.../org/apache/logging/log4j/util/LoaderUtil.java | 21 +--
.../java/org/apache/logging/log4j/util/Unbox.java | 5 +-
.../log4j/core/async/AsyncThreadContextTest.java | 7 +-
.../core/impl/ThreadContextDataInjectorTest.java | 9 +-
.../org/apache/logging/log4j/core/util/Loader.java | 5 +-
.../gctests/GcFreeAsynchronousLoggingTest.java | 3 +-
.../log4j/gctests/GcFreeLoggingTestUtil.java | 5 +-
.../gctests/GcFreeMixedSyncAyncLoggingTest.java | 3 +-
.../gctests/GcFreeSynchronousLoggingTest.java | 3 +-
.../gctests/JsonTemplateLayoutGcFreeTest.java | 5 +-
.../jmh/ConcurrentAsyncLoggerToFileBenchmark.java | 3 +-
.../perf/jmh/FileAppenderThrowableBenchmark.java | 3 +-
.../GarbageFreeOpenHashMapThreadContextMap.java | 2 +-
28 files changed, 261 insertions(+), 93 deletions(-)
diff --git
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
b/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
index 18f680b7c6..a93a7cbc30 100644
---
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
+++
b/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.logging.log4j;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.test.junit.InitializesThreadContext;
import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
import org.junit.jupiter.api.Test;
@@ -29,8 +30,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
public class NoopThreadContextTest {
@Test
- @SetSystemProperty(key = "log4j2.disableThreadContext", value = "true")
- @SetSystemProperty(key = "log4j2.disableThreadContextMap", value = "true")
+ @SetSystemProperty(key = LoggingSystemProperties.THREAD_CONTEXT_DISABLED,
value = "true")
+ @SetSystemProperty(key =
LoggingSystemProperties.THREAD_CONTEXT_MAP_DISABLED, value = "true")
@InitializesThreadContext
@UsingThreadContextMap
public void testNoop() {
diff --git
a/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
b/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
index 2be494111d..0d31ce33d6 100644
---
a/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
+++
b/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
@@ -24,13 +24,13 @@ import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
-import static
org.apache.logging.log4j.spi.LoggingSystem.THREAD_CONTEXT_MAP_INHERITABLE_ENABLED;
+import static
org.apache.logging.log4j.spi.LoggingSystemProperties.THREAD_CONTEXT_MAP_INHERITABLE;
import static org.junit.jupiter.api.Assertions.*;
/**
* Tests {@link ThreadContext}.
*/
-@SetSystemProperty(key = THREAD_CONTEXT_MAP_INHERITABLE_ENABLED, value =
"true")
+@SetSystemProperty(key = THREAD_CONTEXT_MAP_INHERITABLE, value = "true")
@InitializesThreadContext
public class ThreadContextInheritanceTest {
@@ -45,7 +45,7 @@ public class ThreadContextInheritanceTest {
}
@Test
- @SetSystemProperty(key = THREAD_CONTEXT_MAP_INHERITABLE_ENABLED, value =
"true")
+ @SetSystemProperty(key = THREAD_CONTEXT_MAP_INHERITABLE, value = "true")
@InitializesThreadContext
public void testInheritanceSwitchedOn() throws Exception {
ThreadContext.put("Greeting", "Hello");
diff --git
a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java
b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java
index e217f7241d..fa336d1941 100644
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java
@@ -14,9 +14,9 @@
* See the license for the specific language governing permissions and
* limitations under the license.
*/
-
package org.apache.logging.log4j.util;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
@@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.*;
public class Unbox1Test {
@BeforeAll
public static void beforeClass() {
- System.clearProperty("log4j.unbox.ringbuffer.size");
+ System.clearProperty(LoggingSystemProperties.UNBOX_RING_BUFFER_SIZE);
}
@Test
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
b/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
index fc22c18a06..1f8dec7827 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
@@ -24,6 +24,7 @@ import
org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
import org.apache.logging.log4j.spi.LoggerContext;
import org.apache.logging.log4j.spi.LoggerContextFactory;
import org.apache.logging.log4j.spi.LoggingSystem;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.spi.Terminable;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.StackLocatorUtil;
@@ -44,7 +45,7 @@ public class LogManager {
* Log4j property to set to the fully qualified class name of a custom
implementation of
* {@link org.apache.logging.log4j.spi.LoggerContextFactory}.
*/
- public static final String FACTORY_PROPERTY_NAME =
"log4j2.loggerContextFactory";
+ public static final String FACTORY_PROPERTY_NAME =
LoggingSystemProperties.LOGGER_CONTEXT_FACTORY_CLASS;
/**
* The name of the root Logger is {@value #ROOT_LOGGER_NAME}.
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
b/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
index 6041106157..5711276ef5 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
@@ -28,6 +28,7 @@ import java.util.NoSuchElementException;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.spi.DefaultThreadContextMap;
import org.apache.logging.log4j.spi.LoggingSystem;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.spi.ReadOnlyThreadContextMap;
import org.apache.logging.log4j.spi.ThreadContextMap;
import org.apache.logging.log4j.spi.ThreadContextStack;
@@ -37,7 +38,7 @@ import org.apache.logging.log4j.util.InternalApi;
* The ThreadContext allows applications to store information either in a Map
or a Stack.
* <p>
* <b><em>The MDC is managed on a per thread basis</em></b>. To enable
automatic inheritance of <i>copies</i> of the MDC
- * to newly created threads, enable the {@value
org.apache.logging.log4j.spi.LoggingSystem#THREAD_CONTEXT_MAP_INHERITABLE_ENABLED}
+ * to newly created threads, enable the {@value
LoggingSystemProperties#THREAD_CONTEXT_MAP_INHERITABLE}
* Log4j system property.
* </p>
* @see <a
href="https://logging.apache.org/log4j/2.x/manual/thread-context.html">Thread
Context Manual</a>
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessageJsonFormatter.java
b/log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessageJsonFormatter.java
index 35d544aa6d..89b840a34e 100644
---
a/log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessageJsonFormatter.java
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/message/MapMessageJsonFormatter.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.util.IndexedStringMap;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.StringBuilderFormattable;
@@ -42,8 +43,8 @@ import org.apache.logging.log4j.util.StringBuilders;
* <li>{@link String}
* </ul>
* <p>
- * It supports nesting up to a maximum depth of 8, which is set by
- * <tt>log4j2.mapMessage.jsonFormatter.maxDepth</tt> property.
+ * It supports nesting up to a maximum depth of 8, which is set by the
+ * {@value
LoggingSystemProperties#LOGGER_MAP_MESSAGE_JSON_FORMATTER_MAX_DEPTH} property.
*/
enum MapMessageJsonFormatter {;
@@ -66,7 +67,7 @@ enum MapMessageJsonFormatter {;
private static int readMaxDepth() {
final int maxDepth = PropertiesUtil
.getProperties()
-
.getIntegerProperty("log4j2.mapMessage.jsonFormatter.maxDepth", 8);
+
.getIntegerProperty(LoggingSystemProperties.LOGGER_MAP_MESSAGE_JSON_FORMATTER_MAX_DEPTH,
8);
if (maxDepth < 0) {
throw new IllegalArgumentException(
"was expecting a positive maxDepth, found: " + maxDepth);
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
index 3c47e0e240..c5b3114711 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
@@ -91,14 +91,14 @@ public abstract class AbstractLogger implements
ExtendedLogger, Serializable {
* The default MessageFactory class.
*/
public static final Class<? extends MessageFactory>
DEFAULT_MESSAGE_FACTORY_CLASS =
- createClassForProperty("log4j2.messageFactory",
ReusableMessageFactory.class,
+
createClassForProperty(LoggingSystemProperties.LOGGER_MESSAGE_FACTORY_CLASS,
ReusableMessageFactory.class,
ParameterizedMessageFactory.class);
/**
* The default FlowMessageFactory class.
*/
public static final Class<? extends FlowMessageFactory>
DEFAULT_FLOW_MESSAGE_FACTORY_CLASS =
- createFlowClassForProperty("log4j2.flowMessageFactory",
DefaultFlowMessageFactory.class);
+
createFlowClassForProperty(LoggingSystemProperties.LOGGER_FLOW_MESSAGE_FACTORY_CLASS,
DefaultFlowMessageFactory.class);
private static final long serialVersionUID = 2L;
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
index 9846698891..7650c79b58 100644
---
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
@@ -26,7 +26,8 @@ import org.apache.logging.log4j.util.ReadOnlyStringMap;
import org.apache.logging.log4j.util.SortedArrayStringMap;
import org.apache.logging.log4j.util.StringMap;
-import static org.apache.logging.log4j.spi.LoggingSystem.*;
+import static
org.apache.logging.log4j.spi.LoggingSystem.THREAD_CONTEXT_DEFAULT_INITIAL_CAPACITY;
+import static org.apache.logging.log4j.spi.LoggingSystemProperties.*;
/**
* {@code SortedArrayStringMap}-based implementation of the {@code
ThreadContextMap} interface that creates a copy of
@@ -50,7 +51,7 @@ class CopyOnWriteSortedArrayThreadContextMap implements
ReadOnlyThreadContextMap
public CopyOnWriteSortedArrayThreadContextMap() {
this(
-
PropertiesUtil.getProperties().getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE_ENABLED),
+
PropertiesUtil.getProperties().getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE),
PropertiesUtil.getProperties().getIntegerProperty(THREAD_CONTEXT_INITIAL_CAPACITY,
THREAD_CONTEXT_DEFAULT_INITIAL_CAPACITY)
);
}
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
index 816c4051ad..f369803c63 100644
---
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
@@ -27,7 +27,7 @@ import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.ReadOnlyStringMap;
import org.apache.logging.log4j.util.TriConsumer;
-import static
org.apache.logging.log4j.spi.LoggingSystem.THREAD_CONTEXT_MAP_INHERITABLE_ENABLED;
+import static
org.apache.logging.log4j.spi.LoggingSystemProperties.THREAD_CONTEXT_MAP_INHERITABLE;
/**
* The actual ThreadContext Map. A new ThreadContext Map is created each time
it is updated and the Map stored is always
@@ -42,7 +42,7 @@ public class DefaultThreadContextMap implements
ThreadContextMap, ReadOnlyString
* Property name ({@value} ) for selecting {@code InheritableThreadLocal}
(value "true") or plain
* {@code ThreadLocal} (value is not "true") in the implementation.
*/
- public static final String INHERITABLE_MAP =
THREAD_CONTEXT_MAP_INHERITABLE_ENABLED;
+ public static final String INHERITABLE_MAP =
THREAD_CONTEXT_MAP_INHERITABLE;
private final boolean useMap;
private final ThreadLocal<Map<String, String>> localMap;
@@ -65,7 +65,7 @@ public class DefaultThreadContextMap implements
ThreadContextMap, ReadOnlyString
}
public DefaultThreadContextMap(final boolean useMap) {
- this(useMap,
PropertiesUtil.getProperties().getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE_ENABLED));
+ this(useMap,
PropertiesUtil.getProperties().getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE));
}
DefaultThreadContextMap(final boolean useMap, final boolean
inheritableMap) {
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
index cb516827a6..2a258c441c 100644
---
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
@@ -26,7 +26,8 @@ import org.apache.logging.log4j.util.ReadOnlyStringMap;
import org.apache.logging.log4j.util.SortedArrayStringMap;
import org.apache.logging.log4j.util.StringMap;
-import static org.apache.logging.log4j.spi.LoggingSystem.*;
+import static
org.apache.logging.log4j.spi.LoggingSystem.THREAD_CONTEXT_DEFAULT_INITIAL_CAPACITY;
+import static org.apache.logging.log4j.spi.LoggingSystemProperties.*;
/**
* {@code SortedArrayStringMap}-based implementation of the {@code
ThreadContextMap} interface that attempts not to
@@ -44,7 +45,7 @@ class GarbageFreeSortedArrayThreadContextMap implements
ReadOnlyThreadContextMap
public GarbageFreeSortedArrayThreadContextMap() {
this(
-
PropertiesUtil.getProperties().getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE_ENABLED),
+
PropertiesUtil.getProperties().getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE),
PropertiesUtil.getProperties().getIntegerProperty(THREAD_CONTEXT_INITIAL_CAPACITY,
THREAD_CONTEXT_DEFAULT_INITIAL_CAPACITY)
);
}
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java
index 13c5c87347..411887f8a4 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystem.java
@@ -43,6 +43,8 @@ import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.PropertyEnvironment;
import org.apache.logging.log4j.util.ServiceRegistry;
+import static org.apache.logging.log4j.spi.LoggingSystemProperties.*;
+
/**
* Handles initializing the Log4j API through {@link Provider} discovery. This
keeps track of which
* {@link LoggerContextFactory} to use in {@link LogManager} along with
factories for {@link ThreadContextMap}
@@ -58,18 +60,7 @@ public class LoggingSystem {
private static final String API_VERSION = "Log4jAPIVersion";
private static final String[] COMPATIBLE_API_VERSIONS = {"3.0.0"};
- public static final String THREAD_CONTEXT_MAP_DISABLED =
"log4j2.disableThreadContextMap";
- public static final String THREAD_CONTEXT_STACK_DISABLED =
"log4j2.disableThreadContextStack";
- public static final String THREAD_CONTEXT_DISABLED =
"log4j2.disableThreadContext";
- /**
- * Property name ({@value} ) for selecting {@code InheritableThreadLocal}
(value "true") or plain
- * {@code ThreadLocal} (value is not "true") in the {@link
ThreadContextMap} implementation.
- */
- public static final String THREAD_CONTEXT_MAP_INHERITABLE_ENABLED =
"log4j2.isThreadContextMapInheritable";
- public static final String THREAD_CONTEXT_MAP_CLASS_NAME =
"log4j2.threadContextMap";
- public static final String THREAD_CONTEXT_INITIAL_CAPACITY =
"log4j2.threadContextInitialCapacity";
public static final int THREAD_CONTEXT_DEFAULT_INITIAL_CAPACITY = 16;
- public static final String THREAD_CONTEXT_GARBAGE_FREE_ENABLED =
"log4j2.garbagefreeThreadContextMap";
private static final Lazy<LoggingSystem> SYSTEM =
Lazy.relaxed(LoggingSystem::new);
@@ -301,10 +292,10 @@ public class LoggingSystem {
* Creates the ThreadContextMap instance used by the ThreadContext.
* <p>
* If {@linkplain Constants#isThreadLocalsEnabled() Log4j can use
ThreadLocals}, a garbage-free StringMap-based context map can
- * be installed by setting system property {@value
#THREAD_CONTEXT_GARBAGE_FREE_ENABLED} to {@code true}.
+ * be installed by setting system property {@value
LoggingSystemProperties#THREAD_CONTEXT_GARBAGE_FREE_ENABLED} to {@code true}.
* </p><p>
* Furthermore, any custom {@code ThreadContextMap} can be installed
by setting system property
- * {@value #THREAD_CONTEXT_MAP_CLASS_NAME} to the fully qualified
class name of the class implementing the
+ * {@value LoggingSystemProperties#THREAD_CONTEXT_MAP_CLASS} to the
fully qualified class name of the class implementing the
* {@code ThreadContextMap} interface. (Also implement the {@code
ReadOnlyThreadContextMap} interface if your custom
* {@code ThreadContextMap} implementation should be accessible to
applications via the
* {@link ThreadContext#getThreadContextMap()} method.)
@@ -319,7 +310,7 @@ public class LoggingSystem {
*/
public ThreadContextMap createContextMap() {
final PropertyEnvironment environment =
PropertiesUtil.getProperties();
- final String customThreadContextMap =
environment.getStringProperty(THREAD_CONTEXT_MAP_CLASS_NAME);
+ final String customThreadContextMap =
environment.getStringProperty(THREAD_CONTEXT_MAP_CLASS);
if (customThreadContextMap != null) {
final ThreadContextMap customContextMap =
createCustomContextMap(customThreadContextMap);
if (customContextMap != null) {
@@ -340,7 +331,7 @@ public class LoggingSystem {
}
final boolean threadLocalsEnabled =
Constants.isThreadLocalsEnabled();
final boolean garbageFreeEnabled =
environment.getBooleanProperty(THREAD_CONTEXT_GARBAGE_FREE_ENABLED);
- final boolean inheritableMap =
environment.getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE_ENABLED);
+ final boolean inheritableMap =
environment.getBooleanProperty(THREAD_CONTEXT_MAP_INHERITABLE);
final int initialCapacity =
environment.getIntegerProperty(THREAD_CONTEXT_INITIAL_CAPACITY,
THREAD_CONTEXT_DEFAULT_INITIAL_CAPACITY);
if (threadLocalsEnabled) {
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystemProperties.java
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystemProperties.java
new file mode 100644
index 0000000000..7ee8868f22
--- /dev/null
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggingSystemProperties.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.logging.log4j.spi;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.message.FlowMessageFactory;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.status.StatusListener;
+import org.apache.logging.log4j.util.EnvironmentPropertySource;
+import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.apache.logging.log4j.util.Unbox;
+
+/**
+ * Centralized list of property name constants that can be configured in the
Log4j API. These properties may be
+ * specified as system properties, environment variables (see {@link
EnvironmentPropertySource}), or in a classpath
+ * resource file named {@code log4j2.component.properties}.
+ *
+ * @since 3.0.0
+ * @see PropertiesUtil
+ */
+public final class LoggingSystemProperties {
+
+ /**
+ * Property to enable TRACE-level debug logging in the Log4j system itself.
+ * <p>
+ * If property {@value} is either defined empty or its value equals to
{@code true} (ignoring case), all internal
+ * logging will be printed to the console. The presence of this system
property overrides any value set in the
+ * configuration's {@code <Configuration status="<level>" ...>} status
attribute, as well as any value set for
+ * system property {@code log4j2.simplelogStatusLoggerLevel}.
+ * </p>
+ */
+ public static final String SYSTEM_DEBUG = "log4j2.debug";
+
+ /**
+ * Property to override webapp detection. Without this property, the
presence of the {@code Servlet} interface
+ * (from either {@code javax} or {@code jakarta}) is checked to see if
this is a webapp.
+ */
+ public static final String SYSTEM_IS_WEBAPP = "log4j2.isWebapp";
+
+ /**
+ * Property to override the use of thread-local values for garbage-free
logging.
+ *
+ * @see <a
href="https://issues.apache.org/jira/browse/LOG4J2-1270">LOG4J2-1270</a>
+ */
+ public static final String SYSTEM_THREAD_LOCALS_ENABLED =
"log4j2.enableThreadlocals";
+
+ /**
+ * Property to ignore the thread context ClassLoader when set to {@code
true}.
+ *
+ * @see LoaderUtil
+ */
+ public static final String LOADER_IGNORE_THREAD_CONTEXT_LOADER =
"log4j2.ignoreTCL";
+
+ /**
+ * Property to force use of the thread context ClassLoader.
+ *
+ * @see LoaderUtil
+ */
+ public static final String LOADER_FORCE_THREAD_CONTEXT_LOADER =
"log4j2.forceTCLOnly";
+
+ /**
+ * Property to override the default ringbuffer size used in {@link Unbox}.
+ */
+ public static final String UNBOX_RING_BUFFER_SIZE =
"log4j2.unboxRingbufferSize";
+
+ /**
+ * Property to set to the fully qualified class name of a custom
implementation of {@link LoggerContextFactory}.
+ */
+ public static final String LOGGER_CONTEXT_FACTORY_CLASS =
"log4j2.loggerContextFactory";
+
+ /**
+ * Property to override the default {@link MessageFactory} class.
+ */
+ public static final String LOGGER_MESSAGE_FACTORY_CLASS =
"log4j2.messageFactory";
+
+ /**
+ * Property to override the default {@link FlowMessageFactory} class.
+ */
+ public static final String LOGGER_FLOW_MESSAGE_FACTORY_CLASS =
"log4j2.flowMessageFactory";
+
+ /**
+ * Property to override the default maximum nesting depth of map messages
to format in JSON output. The
+ * default value is 8.
+ */
+ public static final String LOGGER_MAP_MESSAGE_JSON_FORMATTER_MAX_DEPTH =
"log4j2.mapMessageJsonFormatterMaxDepth";
+
+ /**
+ * Property to override the maximum size of the StringBuilder instances
used in ringbuffer log events to store
+ * the contents of reusable messages. After delivering messages above this
size to appenders, the StringBuilder
+ * is trimmed to this maximum size. The default value is 518 which allows
the StringBuilder to resize three times
+ * from its initial size.
+ */
+ public static final String LOGGER_REUSABLE_MESSAGE_MAX_SIZE =
"log4j2.maxReusableMsgSize";
+
+ /**
+ * Property that can be configured with the maximum number of status data
entries to keep queued. Once the limit is
+ * reached, older entries will be removed as new entries are added. The
default value is 200.
+ */
+ public static final String STATUS_MAX_ENTRIES = "log4j2.statusEntries";
+
+ /**
+ * Property that can be configured with the {@link Level} name to use as
the default level for
+ * {@link StatusListener}s. The default value is {@link Level#WARN}.
+ */
+ public static final String STATUS_DEFAULT_LISTENER_LEVEL =
"log4j2.statusLoggerLevel";
+
+ /**
+ * Property that can be configured with a date-time format string to use
as the format for timestamps
+ * in the status logger output. See {@link java.text.SimpleDateFormat} for
supported formats.
+ */
+ public static final String STATUS_DATE_FORMAT =
"log4j2.statusLoggerDateFormat";
+
+ /**
+ * Property to control whether {@link ThreadContext} stores map data. If
set to {@code true}, then the
+ * thread context map will be disabled.
+ */
+ public static final String THREAD_CONTEXT_MAP_DISABLED =
"log4j2.disableThreadContextMap";
+
+ /**
+ * Property to control whether {@link ThreadContext} stores stack data. If
set to {@code true}, then the
+ * thread context stack will be disabled.
+ */
+ public static final String THREAD_CONTEXT_STACK_DISABLED =
"log4j2.disableThreadContextStack";
+
+ /**
+ * Property to control whether {@link ThreadContext} stores any data. If
set to {@code true}, then the
+ * thread context map and stack will be disabled.
+ */
+ public static final String THREAD_CONTEXT_DISABLED =
"log4j2.disableThreadContext";
+
+ /**
+ * Property to control whether {@link ThreadContextMap} uses {@link
InheritableThreadLocal} when {@code true} or
+ * {@link ThreadLocal} otherwise for holding map data.
+ */
+ public static final String THREAD_CONTEXT_MAP_INHERITABLE =
"log4j2.isThreadContextMapInheritable";
+
+ /**
+ * Property to override the default {@link ThreadContextMap} class. Note
that implementation classes should
+ * also implement {@link ReadOnlyThreadContextMap} if they should be
accessible to applications via
+ * {@link ThreadContext#getThreadContextMap()}.
+ */
+ public static final String THREAD_CONTEXT_MAP_CLASS =
"log4j2.threadContextMap";
+
+ /**
+ * Property to override the initial capacity of the thread context map.
The default value is 16.
+ */
+ public static final String THREAD_CONTEXT_INITIAL_CAPACITY =
"log4j2.threadContextInitialCapacity";
+
+ /**
+ * Property to override whether to use a garbage-free implementation of
{@link ThreadContextMap}.
+ */
+ public static final String THREAD_CONTEXT_GARBAGE_FREE_ENABLED =
"log4j2.garbagefreeThreadContextMap";
+
+ private LoggingSystemProperties() {
+ throw new UnsupportedOperationException("Utility class");
+ }
+}
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
index f46ffec06b..c458b88a9e 100644
---
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
@@ -20,8 +20,9 @@ import java.util.HashMap;
import java.util.Map;
/**
- * {@code ThreadContextMap} implementation used when either of system
properties {@code disableThreadContextMap} or .
- * {@code disableThreadContext} is {@code true}. This implementation does
nothing.
+ * {@code ThreadContextMap} implementation used when either of system
properties
+ * {@value LoggingSystemProperties#THREAD_CONTEXT_MAP_DISABLED} or
+ * {@value LoggingSystemProperties#THREAD_CONTEXT_DISABLED} is {@code true}.
This implementation does nothing.
*
* @since 2.7
*/
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
b/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
index d6dba83a12..f3b894f65b 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
@@ -37,7 +37,7 @@ import
org.apache.logging.log4j.message.ParameterizedNoReferenceMessageFactory;
import org.apache.logging.log4j.simple.SimpleLogger;
import org.apache.logging.log4j.simple.SimpleLoggerContext;
import org.apache.logging.log4j.spi.AbstractLogger;
-import org.apache.logging.log4j.util.Constants;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.util.LowLevelLogUtil;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.PropertyEnvironment;
@@ -57,20 +57,20 @@ public final class StatusLogger extends AbstractLogger {
* System property that can be configured with the number of entries in
the queue. Once the limit is reached older
* entries will be removed as new entries are added.
*/
- public static final String MAX_STATUS_ENTRIES = "log4j2.status.entries";
+ public static final String MAX_STATUS_ENTRIES =
LoggingSystemProperties.STATUS_MAX_ENTRIES;
/**
* System property that can be configured with the {@link Level} name to
use as the default level for
* {@link StatusListener}s.
*/
- public static final String DEFAULT_STATUS_LISTENER_LEVEL =
"log4j2.StatusLogger.level";
+ public static final String DEFAULT_STATUS_LISTENER_LEVEL =
LoggingSystemProperties.STATUS_DEFAULT_LISTENER_LEVEL;
/**
* System property that can be configured with a date-time format string
to use as the format for timestamps
* in the status logger output. See {@link java.text.SimpleDateFormat} for
supported formats.
* @since 2.11.0
*/
- public static final String STATUS_DATE_FORMAT =
"log4j2.StatusLogger.DateFormat";
+ public static final String STATUS_DATE_FORMAT =
LoggingSystemProperties.STATUS_DATE_FORMAT;
private static final long serialVersionUID = 2L;
@@ -84,7 +84,7 @@ public final class StatusLogger extends AbstractLogger {
static final boolean DEBUG_ENABLED = PropertiesUtil
.getProperties()
- .getBooleanProperty(Constants.LOG4J2_DEBUG, false, true);
+ .getBooleanProperty(LoggingSystemProperties.SYSTEM_DEBUG, false,
true);
// LOG4J2-1176: normal parameterized message remembers param object,
causing memory leaks.
private static final StatusLogger STATUS_LOGGER = new StatusLogger(
@@ -119,7 +119,7 @@ public final class StatusLogger extends AbstractLogger {
* This is now the logger level is set:
* </p>
* <ol>
- * <li>If the property {@value Constants#LOG4J2_DEBUG} is {@code "true"},
then use {@link Level#TRACE}, otherwise,</li>
+ * <li>If the property {@value LoggingSystemProperties#SYSTEM_DEBUG} is
{@code "true"}, then use {@link Level#TRACE}, otherwise,</li>
* <li>Use {@link Level#ERROR}</li>
* </ol>
* <p>
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
index 11260e74b6..d11a2a8269 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
@@ -16,6 +16,8 @@
*/
package org.apache.logging.log4j.util;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
+
/**
* Log4j API Constants.
*
@@ -25,7 +27,7 @@ package org.apache.logging.log4j.util;
public final class Constants {
private static final LazyBoolean isWebApp = new LazyBoolean(() ->
PropertiesUtil.getProperties()
- .getBooleanProperty("log4j2.is.webapp",
+ .getBooleanProperty(LoggingSystemProperties.SYSTEM_IS_WEBAPP,
isClassAvailable("javax.servlet.Servlet") ||
isClassAvailable("jakarta.servlet.Servlet")));
/**
@@ -52,7 +54,7 @@ public final class Constants {
public static final boolean IS_WEB_APP = isWebApp();
private static final LazyBoolean threadLocalsEnabled = new LazyBoolean(
- () -> !isWebApp() &&
PropertiesUtil.getProperties().getBooleanProperty("log4j2.enable.threadlocals",
true));
+ () -> !isWebApp() &&
PropertiesUtil.getProperties().getBooleanProperty(LoggingSystemProperties.SYSTEM_THREAD_LOCALS_ENABLED,
true));
/**
* Kill switch for object pooling in ThreadLocals that enables much of the
LOG4J2-1270 no-GC behaviour.
@@ -86,22 +88,11 @@ public final class Constants {
* After a large message has been delivered to the appenders, the
StringBuilder is trimmed to this size.
* <p>
* The default value is 518, which allows the StringBuilder to resize
three times from its initial size.
- * Users can override with system property "log4j.maxReusableMsgSize".
+ * Users can override with system property {@value
LoggingSystemProperties#LOGGER_REUSABLE_MESSAGE_MAX_SIZE}.
* </p>
* @since 2.9
*/
- public static final int MAX_REUSABLE_MESSAGE_SIZE =
size("log4j.maxReusableMsgSize", (128 * 2 + 2) * 2 + 2);
-
- /**
- * Name of the system property that will turn on TRACE level internal
log4j2 status logging.
- * <p>
- * If system property {@value} is either defined empty or its value equals
to {@code true} (ignoring case), all internal log4j2 logging will be
- * printed to the console. The presence of this system property overrides
any value set in the configuration's
- * {@code <Configuration status="<level>" ...>} status attribute, as well
as any value set for
- * system property {@code
org.apache.logging.log4j.simplelog.StatusLogger.level}.
- * </p>
- */
- public static final String LOG4J2_DEBUG = "log4j2.debug";
+ public static final int MAX_REUSABLE_MESSAGE_SIZE =
size(LoggingSystemProperties.LOGGER_REUSABLE_MESSAGE_MAX_SIZE, (128 * 2 + 2) *
2 + 2);
private static int size(final String property, final int defaultValue) {
return PropertiesUtil.getProperties().getIntegerProperty(property,
defaultValue);
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
b/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
index 5ba881a4af..14c4af7dd8 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
@@ -26,6 +26,8 @@ import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.Objects;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
+
/**
* <em>Consider this class private.</em> Utility class for ClassLoaders.
*
@@ -39,14 +41,6 @@ public final class LoaderUtil {
private static final ClassLoader[] EMPTY_CLASS_LOADER_ARRAY = {};
- /**
- * System property to set to ignore the thread context ClassLoader.
- *
- * @since 2.1
- */
- public static final String IGNORE_TCCL_PROPERTY = "log4j.ignoreTCL";
- public static final String FORCE_TCL_ONLY_PROPERTY = "log4j.forceTCLOnly";
-
private static final SecurityManager SECURITY_MANAGER =
System.getSecurityManager();
// this variable must be lazily loaded; otherwise, we get a nice circular
class loading problem where LoaderUtil
@@ -218,8 +212,9 @@ public final class LoaderUtil {
}
/**
- * Loads a class by name. This method respects the {@link
#IGNORE_TCCL_PROPERTY} Log4j property. If this property is
- * specified and set to anything besides {@code false}, then the default
ClassLoader will be used.
+ * Loads a class by name. This method respects the {@value
LoggingSystemProperties#LOADER_IGNORE_THREAD_CONTEXT_LOADER}
+ * Log4j property. If this property is specified and set to anything
besides {@code false}, then this class's
+ * ClassLoader will be used as specified by {@link Class#forName(String)}.
*
* @param className The class name.
* @return the Class for the given name.
@@ -326,7 +321,7 @@ public final class LoaderUtil {
private static boolean isIgnoreTccl() {
// we need to lazily initialize this, but concurrent access is not an
issue
if (ignoreTCCL == null) {
- final String ignoreTccl =
PropertiesUtil.getProperties().getStringProperty(IGNORE_TCCL_PROPERTY, null);
+ final String ignoreTccl =
PropertiesUtil.getProperties().getStringProperty(LoggingSystemProperties.LOADER_IGNORE_THREAD_CONTEXT_LOADER,
null);
ignoreTCCL = ignoreTccl != null &&
!"false".equalsIgnoreCase(ignoreTccl.trim());
}
return ignoreTCCL;
@@ -337,8 +332,8 @@ public final class LoaderUtil {
// PropertiesUtil.getProperties() uses that code path so don't use
that!
try {
forceTcclOnly = System.getSecurityManager() == null ?
- Boolean.getBoolean(FORCE_TCL_ONLY_PROPERTY) :
- AccessController.doPrivileged((PrivilegedAction<Boolean>)
() -> Boolean.getBoolean(FORCE_TCL_ONLY_PROPERTY));
+
Boolean.getBoolean(LoggingSystemProperties.LOADER_FORCE_THREAD_CONTEXT_LOADER) :
+ AccessController.doPrivileged((PrivilegedAction<Boolean>)
() ->
Boolean.getBoolean(LoggingSystemProperties.LOADER_FORCE_THREAD_CONTEXT_LOADER));
} catch (final SecurityException se) {
forceTcclOnly = false;
}
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
b/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
index adad8a4947..3c5907bb9f 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.util;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.status.StatusLogger;
/**
@@ -40,7 +41,7 @@ import org.apache.logging.log4j.status.StatusLogger;
* have up to 32 boxed primitives in a single logger call.
* </p>
* <p>
- * If more slots are required, set system property {@code
log4j.unbox.ringbuffer.size} to the desired ring buffer size.
+ * If more slots are required, set system property {@value
LoggingSystemProperties#UNBOX_RING_BUFFER_SIZE} to the desired ring buffer size.
* Note that the specified number will be rounded up to the nearest power of 2.
* </p>
* @since 2.6
@@ -50,7 +51,7 @@ public class Unbox {
private static final Logger LOGGER = StatusLogger.getLogger();
private static final int BITS_PER_INT = 32;
private static final int RINGBUFFER_MIN_SIZE = 32;
- private static final int RINGBUFFER_SIZE =
calculateRingBufferSize("log4j.unbox.ringbuffer.size");
+ private static final int RINGBUFFER_SIZE =
calculateRingBufferSize(LoggingSystemProperties.UNBOX_RING_BUFFER_SIZE);
private static final int MASK = RINGBUFFER_SIZE - 1;
/**
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncThreadContextTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncThreadContextTest.java
index 27d5ab26a0..8d0c39e9d3 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncThreadContextTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncThreadContextTest.java
@@ -35,6 +35,7 @@ import org.apache.logging.log4j.core.util.NetUtils;
import org.apache.logging.log4j.plugins.di.DI;
import org.apache.logging.log4j.plugins.di.Injector;
import org.apache.logging.log4j.spi.DefaultThreadContextMap;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.spi.ReadOnlyThreadContextMap;
import org.apache.logging.log4j.test.junit.CleanUpFiles;
import org.apache.logging.log4j.util.PropertiesUtil;
@@ -69,8 +70,8 @@ public class AsyncThreadContextTest {
public static void afterClass() {
System.clearProperty("AsyncLogger.RingBufferSize");
System.clearProperty("AsyncLoggerConfig.RingBufferSize");
- System.clearProperty("log4j2.garbagefree.threadContextMap");
- System.clearProperty("log4j2.threadContextMap");
+
System.clearProperty(LoggingSystemProperties.THREAD_CONTEXT_GARBAGE_FREE_ENABLED);
+ System.clearProperty(LoggingSystemProperties.THREAD_CONTEXT_MAP_CLASS);
}
enum Mode {
@@ -91,7 +92,7 @@ public class AsyncThreadContextTest {
WEBAPP, GARBAGE_FREE, COPY_ON_WRITE;
void init() {
- System.clearProperty("log4j2.threadContextMap");
+
System.clearProperty(LoggingSystemProperties.THREAD_CONTEXT_MAP_CLASS);
final String PACKAGE = "org.apache.logging.log4j.spi.";
System.setProperty("log4j2.threadContextMap", PACKAGE +
implClassSimpleName());
((PropertiesUtil) PropertiesUtil.getProperties()).reload();
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjectorTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjectorTest.java
index e067ebdb11..78f071df37 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjectorTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThreadContextDataInjectorTest.java
@@ -21,6 +21,7 @@ import java.util.concurrent.ExecutionException;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.ContextDataInjector;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.spi.ReadOnlyThreadContextMap;
import org.apache.logging.log4j.test.ThreadContextUtilityClass;
import org.apache.logging.log4j.util.PropertiesUtil;
@@ -60,15 +61,15 @@ public class ThreadContextDataInjectorTest {
@Before
public void before() {
- System.setProperty("log4j2.threadContextMap",
threadContextMapClassName);
+ System.setProperty(LoggingSystemProperties.THREAD_CONTEXT_MAP_CLASS,
threadContextMapClassName);
}
@After
public void after() {
ThreadContext.remove("foo");
ThreadContext.remove("baz");
- System.clearProperty("log4j2.threadContextMap");
- System.clearProperty("log4j2.isThreadContextMapInheritable");
+ System.clearProperty(LoggingSystemProperties.THREAD_CONTEXT_MAP_CLASS);
+
System.clearProperty(LoggingSystemProperties.THREAD_CONTEXT_MAP_INHERITABLE);
}
private void testContextDataInjector() {
@@ -101,7 +102,7 @@ public class ThreadContextDataInjectorTest {
}
private void prepareThreadContext(boolean isThreadContextMapInheritable) {
- System.setProperty("log4j2.isThreadContextMapInheritable",
Boolean.toString(isThreadContextMapInheritable));
+
System.setProperty(LoggingSystemProperties.THREAD_CONTEXT_MAP_INHERITABLE,
Boolean.toString(isThreadContextMapInheritable));
((PropertiesUtil) PropertiesUtil.getProperties()).reload();
ThreadContextUtilityClass.reset();
ThreadContext.remove("baz");
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
index d5aa464078..aefbeb9403 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
@@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.LoaderUtil;
import org.apache.logging.log4j.util.PropertiesUtil;
@@ -35,7 +36,7 @@ public final class Loader {
private static final String TSTR = "Caught Exception while in
Loader.getResource. This may be innocuous.";
final static Boolean ignoreTccl =
-
Boolean.valueOf(PropertiesUtil.getProperties().getStringProperty(LoaderUtil.IGNORE_TCCL_PROPERTY,
null));
+
Boolean.valueOf(PropertiesUtil.getProperties().getStringProperty(LoggingSystemProperties.LOADER_IGNORE_THREAD_CONTEXT_LOADER,
null));
private Loader() {
}
@@ -297,7 +298,7 @@ public final class Loader {
}
/**
- * Loads a class by name. This method respects the {@link
LoaderUtil#IGNORE_TCCL_PROPERTY} Log4j property. If this property is
+ * Loads a class by name. This method respects the {@link
LoggingSystemProperties#LOADER_IGNORE_THREAD_CONTEXT_LOADER} Log4j property. If
this property is
* specified and set to anything besides {@code false}, then the default
ClassLoader will be used.
*
* @param className The class name.
diff --git
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsynchronousLoggingTest.java
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsynchronousLoggingTest.java
index 0783903ed0..4262d80827 100644
---
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsynchronousLoggingTest.java
+++
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsynchronousLoggingTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.gctests;
import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
import org.apache.logging.log4j.core.test.categories.GarbageFree;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -41,7 +42,7 @@ public class GcFreeAsynchronousLoggingTest {
* This code runs in a separate process, instrumented with the Google
Allocation Instrumenter.
*/
public static void main(final String[] args) throws Exception {
- System.setProperty("log4j2.garbagefree.threadContextMap", "true");
+
System.setProperty(LoggingSystemProperties.THREAD_CONTEXT_GARBAGE_FREE_ENABLED,
"true");
System.setProperty("AsyncLogger.RingBufferSize", "128"); // minimum
ringbuffer size
System.setProperty("Log4jContextSelector",
AsyncLoggerContextSelector.class.getName());
GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml",
GcFreeAsynchronousLoggingTest.class);
diff --git
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeLoggingTestUtil.java
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeLoggingTestUtil.java
index 97e37b5c04..f02009a8aa 100644
---
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeLoggingTestUtil.java
+++
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeLoggingTestUtil.java
@@ -33,6 +33,7 @@ import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.message.StringMapMessage;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import com.google.monitoring.runtime.instrumentation.AllocationRecorder;
import com.google.monitoring.runtime.instrumentation.Sampler;
@@ -51,9 +52,9 @@ public enum GcFreeLoggingTestUtil {;
public static void executeLogging(final String configurationFile,
final Class<?> testClass) throws
Exception {
- System.setProperty("log4j2.enable.threadlocals", "true");
+
System.setProperty(LoggingSystemProperties.SYSTEM_THREAD_LOCALS_ENABLED,
"true");
System.setProperty("log4j2.enable.direct.encoders", "true");
- System.setProperty("log4j2.is.webapp", "false");
+ System.setProperty(LoggingSystemProperties.SYSTEM_IS_WEBAPP, "false");
System.setProperty("log4j.configurationFile", configurationFile);
assertTrue(isThreadLocalsEnabled(), "Constants.ENABLE_THREADLOCALS");
diff --git
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeMixedSyncAyncLoggingTest.java
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeMixedSyncAyncLoggingTest.java
index 12330f2fd0..40796c4d9c 100644
---
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeMixedSyncAyncLoggingTest.java
+++
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeMixedSyncAyncLoggingTest.java
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.gctests;
import org.apache.logging.log4j.core.test.categories.GarbageFree;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -40,7 +41,7 @@ public class GcFreeMixedSyncAyncLoggingTest {
* This code runs in a separate process, instrumented with the Google
Allocation Instrumenter.
*/
public static void main(final String[] args) throws Exception {
- System.setProperty("log4j2.garbagefree.threadContextMap", "true");
+
System.setProperty(LoggingSystemProperties.THREAD_CONTEXT_GARBAGE_FREE_ENABLED,
"true");
System.setProperty("AsyncLoggerConfig.RingBufferSize", "128"); //
minimum ringbuffer size
GcFreeLoggingTestUtil.executeLogging("gcFreeMixedSyncAsyncLogging.xml",
GcFreeMixedSyncAyncLoggingTest.class);
}
diff --git
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeSynchronousLoggingTest.java
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeSynchronousLoggingTest.java
index b76455717e..b5fc0011d4 100644
---
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeSynchronousLoggingTest.java
+++
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/GcFreeSynchronousLoggingTest.java
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.gctests;
import org.apache.logging.log4j.core.test.categories.GarbageFree;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -40,7 +41,7 @@ public class GcFreeSynchronousLoggingTest {
* This code runs in a separate process, instrumented with the Google
Allocation Instrumenter.
*/
public static void main(final String[] args) throws Exception {
- System.setProperty("log4j2.garbagefree.threadContextMap", "true");
+
System.setProperty(LoggingSystemProperties.THREAD_CONTEXT_GARBAGE_FREE_ENABLED,
"true");
GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml",
GcFreeSynchronousLoggingTest.class);
}
}
diff --git
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/JsonTemplateLayoutGcFreeTest.java
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/JsonTemplateLayoutGcFreeTest.java
index ae91963f74..f68cf1678b 100644
---
a/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/JsonTemplateLayoutGcFreeTest.java
+++
b/log4j-gctests/src/test/java/org/apache/logging/log4j/gctests/JsonTemplateLayoutGcFreeTest.java
@@ -16,8 +16,9 @@
*/
package org.apache.logging.log4j.gctests;
-import org.junit.jupiter.api.Test;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
@Tag("allocation")
@Tag("functional")
@@ -33,7 +34,7 @@ public class JsonTemplateLayoutGcFreeTest {
*/
public static void main(final String[] args) throws Exception {
System.setProperty("log4j.layout.jsonTemplate.recyclerFactory",
"threadLocal");
- System.setProperty("log4j2.garbagefree.threadContextMap", "true");
+
System.setProperty(LoggingSystemProperties.THREAD_CONTEXT_GARBAGE_FREE_ENABLED,
"true");
GcFreeLoggingTestUtil.executeLogging(
"gcFreeJsonTemplateLayoutLogging.xml",
JsonTemplateLayoutGcFreeTest.class);
diff --git
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java
index 6540226f60..b09d136fb3 100644
---
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java
+++
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.LifeCycle;
import org.apache.logging.log4j.core.async.AsyncQueueFullPolicy;
import org.apache.logging.log4j.core.async.EventRoute;
import org.apache.logging.log4j.perf.util.BenchmarkMessageParams;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
@@ -85,7 +86,7 @@ public class ConcurrentAsyncLoggerToFileBenchmark {
@Setup
public final void before() throws IOException {
Files.deleteIfExists(Path.of("target",
"ConcurrentAsyncLoggerToFileBenchmark.log"));
- System.setProperty("log4j2.is.webapp", "false");
+ System.setProperty(LoggingSystemProperties.SYSTEM_IS_WEBAPP,
"false");
asyncLoggerType.setProperties();
queueFullPolicy.setProperties();
logger =
LogManager.getLogger(ConcurrentAsyncLoggerToFileBenchmark.class);
diff --git
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java
index cc109ecfda..18870d7ec7 100644
---
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java
+++
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.async.AsyncLoggerContext;
import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.spi.LoggingSystemProperties;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
@@ -60,7 +61,7 @@ import java.util.logging.Level;
public class FileAppenderThrowableBenchmark {
static {
// log4j2
- System.setProperty("log4j2.is.webapp", "false");
+ System.setProperty(LoggingSystemProperties.SYSTEM_IS_WEBAPP, "false");
System.setProperty("log4j.configurationFile",
"log4j2-perf-file-throwable.xml");
// log4j 1.2
System.setProperty("log4j.configuration",
"log4j12-perf-file-throwable.xml");
diff --git
a/log4j-perf/src/main/java/org/apache/logging/log4j/spi/GarbageFreeOpenHashMapThreadContextMap.java
b/log4j-perf/src/main/java/org/apache/logging/log4j/spi/GarbageFreeOpenHashMapThreadContextMap.java
index 9d6f622273..afa9102afc 100644
---
a/log4j-perf/src/main/java/org/apache/logging/log4j/spi/GarbageFreeOpenHashMapThreadContextMap.java
+++
b/log4j-perf/src/main/java/org/apache/logging/log4j/spi/GarbageFreeOpenHashMapThreadContextMap.java
@@ -22,7 +22,7 @@ import org.apache.logging.log4j.util.ReadOnlyStringMap;
import org.apache.logging.log4j.util.StringMap;
import static
org.apache.logging.log4j.spi.LoggingSystem.THREAD_CONTEXT_DEFAULT_INITIAL_CAPACITY;
-import static
org.apache.logging.log4j.spi.LoggingSystem.THREAD_CONTEXT_INITIAL_CAPACITY;
+import static
org.apache.logging.log4j.spi.LoggingSystemProperties.THREAD_CONTEXT_INITIAL_CAPACITY;
/**
* {@code OpenHashStringMap}-based implementation of the {@code
ThreadContextMap} interface that attempts not to