Skip to content

Commit e6044c9

Browse files
committed
Clean up mentions of log4j2.enable.threadLocals property (#2171)
1 parent 7f41487 commit e6044c9

File tree

5 files changed

+7
-111
lines changed

5 files changed

+7
-111
lines changed

src/site/asciidoc/manual/async.adoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,8 @@ command line options we used:
687687
* -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
688688
-DAsyncLogger.WaitStrategy=busyspin (to use Async Loggers. The BusySpin
689689
wait strategy reduces some jitter.)
690-
* *classic mode:* -Dlog4j2.enable.threadlocals=false
691-
-Dlog4j2.enable.direct.encoders=false +
692-
*garbage-free mode:* -Dlog4j2.enable.threadlocals=true
693-
-Dlog4j2.enable.direct.encoders=true
690+
* *classic mode:* -Dlog4j2.enable.direct.encoders=false +
691+
*garbage-free mode:* -Dlog4j2.enable.direct.encoders=true
694692
* -XX:CompileCommand=dontinline,org.apache.logging.log4j.core.async.perftest.NoOpIdleStrategy::idle
695693
* -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps
696694
-XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime

src/site/asciidoc/manual/extending.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,7 @@ declare it as a service by defining the implmentation class in a file named
608608
== Custom ThreadContextMap implementations
609609
610610
A garbage-free `StringMap`-based context map can be installed by setting
611-
system property `log4j2.garbagefreeThreadContextMap` to true. (Log4j
612-
must be link:garbagefree.html#Config[enabled] to use ThreadLocals.)
611+
system property `log4j2.garbagefreeThreadContextMap` to true.
613612
614613
Any custom link:../log4j-core/apidocs/org/apache/logging/log4j/spi/ThreadContextMap.html[`ThreadContextMap`]
615614
implementation can be installed by setting system property `log4j2.threadContextMap`

src/site/asciidoc/manual/garbagefree.adoc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ you may also configure a link:async.html#WaitStrategy[custom wait strategy].)
120120
There are two separate system properties for manually controlling the
121121
mechanisms Log4j uses to avoid creating temporary objects:
122122
123-
* `log4j2.enableThreadlocals` - if "true" (the default for non-web
124-
applications) objects are stored in ThreadLocal fields and reused,
125-
otherwise new objects are created for each log event.
126123
* `log4j2.enableDirectEncoders` - if "true" (the default) log events are
127124
converted to text and this text is converted to bytes without creating
128125
temporary objects. Note: _synchronous_ logging performance may be worse
@@ -386,10 +383,6 @@ http://logging.apache.org/log4j/2.x/log4j-api/xref/org/apache/logging/log4j/util
386383
interface. If an object is logged that implements this interface, its
387384
`formatTo` method is called instead of `toString()`.
388385
389-
Log4j may call `toString()` on message and parameter objects when
390-
garbage-free logging is disabled (when system property
391-
`log4j2.enableThreadlocals` is set to "false".)
392-
393386
[#codeImpact]
394387
=== Impact on Application Code: Autoboxing
395388
@@ -463,10 +456,8 @@ command line options we used:
463456
* -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
464457
-DAsyncLogger.WaitStrategy=busyspin (to use Async Loggers. The BusySpin
465458
wait strategy reduces some jitter.)
466-
* *classic mode:* -Dlog4j2.enable.threadlocals=false
467-
-Dlog4j2.enable.direct.encoders=false +
468-
*garbage-free mode:* -Dlog4j2.enable.threadlocals=true
469-
-Dlog4j2.enable.direct.encoders=true
459+
* *classic mode:* -Dlog4j2.enable.direct.encoders=false +
460+
*garbage-free mode:* -Dlog4j2.enable.direct.encoders=true
470461
* -XX:CompileCommand=dontinline,org.apache.logging.log4j.core.async.perftest.NoOpIdleStrategy::idle
471462
* -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps
472463
-XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime

src/site/asciidoc/manual/json-template-layout.adoc.vm

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -338,48 +338,6 @@ JsonTemplateLayout:
338338
}
339339
----
340340

341-
[#recycling-strategy]
342-
=== Recycling strategy
343-
344-
`RecyclerFactory` plays a crucial role for determining the memory footprint of
345-
the layout. Template resolvers employ it to create recyclers for objects that
346-
they can reuse. The behavior of each `RecyclerFactory` and when one should
347-
prefer one over another is explained below:
348-
349-
* `dummy` performs no recycling, hence each recycling attempt will result in a
350-
new instance. This will obviously create a load on the garbage-collector. It
351-
is a good choice for applications with low and medium log rate.
352-
353-
* `threadLocal` performs the best, since every instance is stored in
354-
``ThreadLocal``s and accessed without any synchronization cost. Though this
355-
might not be a desirable option for applications running with hundreds of
356-
threads or more, e.g., a web servlet.
357-
358-
* `queue` is the best of both worlds. It allows recycling of objects up to a
359-
certain number (`capacity`). When this limit is exceeded due to excessive
360-
concurrent load (e.g., `capacity` is 50 but there are 51 threads concurrently
361-
trying to log), it starts allocating. `queue` is a good strategy where
362-
`threadLocal` is not desirable.
363-
+
364-
`queue` also accepts optional `supplier` (of type `java.util.Queue`, defaults to
365-
`org.jctools.queues.MpmcArrayQueue.new` if JCTools is in the classpath;
366-
otherwise `java.util.concurrent.ArrayBlockingQueue.new`) and `capacity` (of
367-
type `int`, defaults to `max(8,2*cpuCount+1)`) parameters:
368-
+
369-
.Example configurations of `queue` recycling strategy
370-
[source]
371-
----
372-
queue:supplier=org.jctools.queues.MpmcArrayQueue.new
373-
queue:capacity=10
374-
queue:supplier=java.util.concurrent.ArrayBlockingQueue.new,capacity=50
375-
----
376-
377-
The default `RecyclerFactory` is `threadLocal`, if
378-
`log4j2.enable.threadlocals=true`; otherwise, `queue`.
379-
380-
See <<extending-recycler>> for details on how to introduce custom
381-
`RecyclerFactory` implementations.
382-
383341
[#template-config]
384342
== Template Configuration
385343

@@ -1082,8 +1040,7 @@ Resolves `logEvent.getMessage().getParameters()`.
10821040
====
10831041
Regarding garbage footprint, `stringified` flag translates to
10841042
`String.valueOf(value)`, hence mind not-`String`-typed values. Further,
1085-
`logEvent.getMessage()` is expected to implement `ParameterVisitable` interface,
1086-
which is the case if `log4j2.enableThreadLocals` property set to true.
1043+
`logEvent.getMessage()` is expected to implement `ParameterVisitable` interface.
10871044
====
10881045

10891046
====== Examples
@@ -1590,7 +1547,6 @@ plugins:
15901547

15911548
* Event template resolvers (e.g., `exception`, `message`, `level` event template resolvers)
15921549
* Event template interceptors (e.g., injection of `eventTemplateAdditionalField`)
1593-
* Recycler factories
15941550

15951551
Following sections cover these in detail.
15961552

@@ -1829,44 +1785,6 @@ provided an `eventTemplateRootObjectKey`. If so, it wraps the root `node` with a
18291785
new object; otherwise, returns the `node` as is. Note that `node` refers to the
18301786
root Java object of the event template read by `JsonReader`.
18311787

1832-
[#extending-recycler]
1833-
=== Extending Recycler Factories
1834-
1835-
`recyclerFactory` input `String` read from the layout configuration is converted
1836-
to a `RecyclerFactory` using the default `RecyclerFactoryConverter` extending
1837-
from `TypeConverter<RecyclerFactory>`. If one wants to change this behavior,
1838-
they simply need to add their own `TypeConverter<RecyclerFactory>` implementing
1839-
`Comparable<TypeConverter<?>>` to prioritize their custom converter.
1840-
1841-
[source,java]
1842-
.Custom `TypeConverter` for `RecyclerFactory`
1843-
----
1844-
package com.acme.logging.log4j.layout.template.json;
1845-
1846-
import org.apache.logging.log4j.plugins.Plugin;
1847-
import org.apache.logging.log4j.plugins.convert.TypeConverter;
1848-
1849-
@Category(TypeConverter.CATEGORY)
1850-
@Plugin("AcmeRecyclerFactoryConverter")
1851-
public final class AcmeRecyclerFactoryConverter
1852-
implements TypeConverter<RecyclerFactory>, Comparable<TypeConverter<?>> {
1853-
1854-
@Override
1855-
public RecyclerFactory convert(final String recyclerFactorySpec) {
1856-
return AcmeRecyclerFactory.ofSpec(recyclerFactorySpec);
1857-
}
1858-
1859-
@Override
1860-
public int compareTo(final TypeConverter<?> ignored) {
1861-
return -1;
1862-
}
1863-
1864-
}
1865-
----
1866-
1867-
Here note that `compareTo()` always returns -1 to rank it higher compared to
1868-
other matching converters.
1869-
18701788
[#features]
18711789
== Features
18721790

@@ -1966,7 +1884,7 @@ Yes, if the garbage-free layout behaviour toggling properties
19661884
`log4j2.enableDirectEncoders` and `log4j2.garbagefreeThreadContextMap` are
19671885
enabled. Take into account the following caveats:
19681886

1969-
* The configured link:#recycling-strategy[recycling strategy] might not be
1887+
* The configured recycling strategy might not be
19701888
garbage-free.
19711889

19721890
* Since `Throwable#getStackTrace()` clones the original `StackTraceElement[]`,

src/site/asciidoc/manual/systemproperties.adoc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,6 @@ class name of a custom `ThreadContextMap` implementation class.
365365
|If `true` use a `InheritableThreadLocal` to implement the ThreadContext map. Otherwise, use a plain `ThreadLocal`.
366366
(May be ignored if a custom ThreadContext map is specified.)
367367
368-
|ThreadLocals
369-
|enable
370-
|log4j2.enableThreadlocals, LOG4J_ENABLE_THREADLOCALS
371-
|System
372-
|true
373-
|This system property can be used to switch off the use of threadlocals, which will partly disable Log4j's
374-
garbage-free behaviour: to be fully garbage-free, Log4j stores objects in ThreadLocal fields to reuse them,
375-
otherwise new objects are created for each log event. Note that this property is not effective when Log4j
376-
detects it is running in a web application.
377-
378368
|Unbox
379369
|ringBufferSize
380370
|log4j2.unboxRingbufferSize, LOG4J_UNBOX_RINGBUFFER_SIZE

0 commit comments

Comments
 (0)