You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/site/antora/modules/ROOT/pages/manual/async.adoc
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,17 +16,17 @@
16
16
////
17
17
= Asynchronous loggers
18
18
19
-
Asynchronous logging is a technique to improve application logging performance by executing all I/O operations in a separate thread.
19
+
Asynchronous logging is a technique that improves application logging performance by executing all I/O operations in a separate thread.
20
20
21
21
Log4j offers out-of-the-box two different asynchronous logging solutions:
22
22
23
23
Asynchronous appender::
24
-
A classical queue-based asynchronous appender, which is available since Log4j 1.
24
+
An asynchronous appender is a classical queue-based asynchronous appender which is available since Log4j 1.
25
25
+
26
26
See xref:manual/appenders/delegating.adoc#AsyncAppender[Asynchronous appender] for more details.
27
27
28
28
Asynchronous loggers::
29
-
Asynchronous loggers are a new feature available since Log4j 2.
29
+
Asynchronous loggers have been a new feature since Log4j 2.
30
30
They are based on
31
31
{lmax-disruptor-url}[LMAX Disruptor],
32
32
a lock-free inter-thread communication library, instead of queues, resulting in higher throughput and lower latency.
@@ -35,9 +35,9 @@ The rest of this chapter is dedicated to this new component.
35
35
36
36
[WARNING]
37
37
====
38
-
Logging performance depends greatly on the architecture of your application and the way you use logging.
39
-
The solutions offered by this chapter should be evaluated using benchmarks against your own application.
40
-
If benchmarks and profiling don't show a statistically significant difference between asynchronous and synchronous logging solutions, the latter one is recommended, since it is the simplest one.
38
+
Logging performance depends significantly on the architecture of your application and the way you use logging.
39
+
The solutions offered by this chapter should be evaluated using benchmarks against your application.
40
+
If benchmarks and profiling don't show a statistically significant difference between asynchronous and synchronous logging solutions, the latter is recommended since it is the simplest.
If you use `AsyncRoot` and `AsyncLogger` configuration elements, two asynchronous barriers will be created instead of one, which will impair performance.
82
+
If you use `AsyncRoot` and `AsyncLogger` configuration elements, two asynchronous barriers will be created instead of one, impairing performance.
83
83
====
84
84
85
85
[#SysPropsAllAsync]
@@ -91,11 +91,11 @@ Beyond the <<common-configuration-properties,common configuration properties>>,
<1> All the appenders referenced by `Root` and `Logger` are called synchronously.
157
-
This is especially important for audit logging, since exceptions can be forwarded to the caller.
157
+
This is especially important for audit logging since exceptions can be forwarded to the caller.
158
158
<2> All the appenders references by `AsyncRoot` and `AsyncLogger` are called asynchronously.
159
159
These log statements will cause a smaller latency for the caller.
160
160
161
161
[[SysPropsMixedSync-Async]]
162
162
=== Tuning a mixed synchronous/asynchronous configuration
163
163
164
-
Since all `AsyncRoot` and `AsyncLogger` components share the same Disruptor instance, its configuration is available through configuration properties.
164
+
Since all `AsyncRoot` and `AsyncLogger` components share the same Disruptor instance, their configuration is available through configuration properties.
165
165
166
166
Beyond the <<common-configuration-properties,common configuration properties>>, the following additional elements are configurable:
167
167
@@ -177,7 +177,7 @@ See xref:manual/systemproperties.adoc#property-sources[Property Sources] for mor
177
177
[#common-configuration-properties]
178
178
=== Common configuration properties
179
179
180
-
Regardless of the way you configure asynchronous loggers in Log4j, you can use the following properties to further tune your installation:
180
+
Regardless of the way you configure asynchronous loggers in Log4j, you can use the following properties to tune your installation further:
The system properties mentioned in the section above allow only to choose from among a fixed set of wait strategies.
188
188
189
-
In order to use a custom wait strategy you need to:
189
+
To use a custom wait strategy, you need to:
190
190
191
191
. Use the <<MixedSync-Async,mixed sync/async configuration method>> above,
192
192
. Implement the interface link:../javadoc/log4j-core/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactory.html[`AsyncWaitStrategyFactory`]; the implementation must have a public no-arg constructor,
xref:manual/layouts.adoc#LocationInformation[Computing the location information (i.e., the caller class, method, file, and line number) of a log event is an expensive operation.]
235
-
The impact on asynchronous loggers and appenders is even higher, since the component must decide whether to compute it or not **before** crossing the asynchronous barrier.
236
-
Hence, the location information is disabled by default for asynchronous loggers and appenders.
237
-
In order to enable it for a certain logger, set its xref:manual/configuration.adoc#logger-attributes-includeLocation[`includeLocation`] attribute to `true`.
235
+
The impact on asynchronous loggers and appenders is even higher since the component must decide whether to compute it or not **before** crossing the asynchronous barrier.
236
+
Location information is turned off by default for asynchronous loggers and appenders.
237
+
To enable it for a certain logger, set its xref:manual/configuration.adoc#logger-attributes-includeLocation[`includeLocation`] attribute to `true`.
238
238
239
239
[id=exception-handler]
240
240
== Exception handler
241
241
242
-
In order to handle exceptions that occur on the asynchronous thread, you can configure a custom
242
+
To handle exceptions that occur on the asynchronous thread, you can configure a custom
The exact type of handler depends on the configuration mode:
246
246
247
247
Full asynchronous::
248
248
+
249
-
If all the loggers are asynchronous you need to:
249
+
If all the loggers are asynchronous, you need to:
250
250
+
251
251
* implement an link:../javadoc/log4j-core/org/apache/logging/log4j/core/async/RingBufferLogEvent.html[`ExceptionHandler<? super RingBufferLogEvent>`]
252
252
* set its fully qualified class name as value of the
@@ -255,10 +255,10 @@ configuration property.
255
255
256
256
Mixed synchronous/asynchronous::
257
257
+
258
-
If you use a mix of synchronous and asynchronous loggers you need to:
258
+
If you use a mix of synchronous and asynchronous loggers, you need to:
259
259
+
260
260
* implement a
261
261
link:../javadoc/log4j-core/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.Log4jEventWrapper.html[`ExceptionHandler<? super AsyncLoggerConfigDisruptor.Log4jEventWrapper>`]
262
-
* set its fully qualified class name as value of the
262
+
* set its fully qualified class name as the value of the
0 commit comments