Skip to content

Commit 91c2923

Browse files
authoredMay 2, 2024··
Revamp the Concepts in the Installation (#2561)
1 parent abbd774 commit 91c2923

File tree

3 files changed

+161
-76
lines changed

3 files changed

+161
-76
lines changed
 

‎antora-playbook.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ asciidoc:
3838
log4j-docgen-type-filter-exclude-pattern: ^java\..+
3939
log4j-docgen-type-target-template: |
4040
#{{{replaceAll sourcedType.groupId "." "-"}}}_{{{replaceAll sourcedType.artifactId "." "-"}}}_{{{replaceAll sourcedType.type.className "." "-"}}}
41+
# Force Kroki to download images at build time
42+
kroki-fetch-diagram: true
4143
extensions:
4244
- "@asciidoctor/tabs"
45+
- asciidoctor-kroki
4346
- src/docgen/apiref-macro.js
4447

4548
ui:

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"@antora/cli": "^3.2.0-alpha.4",
44
"@antora/site-generator-default": "^3.2.0-alpha.4",
55
"@asciidoctor/tabs": "^1.0.0-beta.6",
6+
"asciidoctor-kroki": "^0.18.1",
67
"fast-xml-parser": "^4.3.6",
78
"handlebars": "^4.7.8"
89
}

‎src/site/antora/modules/ROOT/pages/manual/installation.adoc

+157-76
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,78 @@ In the case of Log4j, the API is called _Log4j API_, and its reference implement
7272
[#logging-bridge]
7373
Logging bridge::
7474
Logging implementations accept input from a single logging API of their preference; Log4j Core from Log4j API, Logback from SLF4J, etc.
75-
A logging bridge is a simple logging implementation of a logging API that forward all messages to a foreign logging API.
75+
A logging bridge is a simple logging implementation of a logging API that forwards all messages to a foreign logging API.
7676
Logging bridges allow a logging implementation to accept input from other logging APIs that are not their primary logging API.
7777
For instance, `log4j-slf4j2-impl` _bridges_ SLF4J calls to Log4 API and effectively enables Log4j Core to accept input from SLF4J.
7878
7979
With this in mind, the type of software you are writing determines whether you should be installing a logging API, implementation, or bridge:
8080
8181
Libraries::
82-
only require a logging API and delegate the choice of the implementation to applications.
82+
They only require a logging API and delegate the choice of the implementation to applications.
8383
If a logging implementation is required by tests of the library, it should be in the appropriate test scope.
8484
8585
Applications::
86-
need a logging implementation, but also bridges of each of the major logging APIs to support log statements from the libraries they use.
86+
They need a logging implementation, but also bridges of each of the major logging APIs to support log statements from the libraries they use.
8787
For instance, your application might be logging against Log4j API and one of its dependencies against SLF4J.
8888
In this case, you need to install `log4j-core` and `log4j-slf4j2-impl`.
8989
(This is an example, we will elaborate on this case more in <<impl-core>>.)
9090
91+
To make things a little bit more tangible, consider the following visualization of a typical Log4j Core installation with bridges for an application:
92+
93+
.Visualization of a typical Log4j Core installation with SLF4J, JUL, and JPL bridges.
94+
[ditaa]
95+
....
96+
/-----------------------------------------------------------------------------------\
97+
| |
98+
| +------------+ +----------+ +----------+ |
99+
| | | | | | | |
100+
| | v | v | v |
101+
| +-----+-----+ +---------+ +---------+ +----+----+ +-------+ +----+----+ +-------+ |
102+
| | | |{d}c1FF | | | | | |{d}c1FF| | | |{d}c1FF| |
103+
| |Application| |Log4j API| |Library 1| |Library 2| | SLF4J | |Library 3| | JUL | |
104+
| | | | | | | | | | | | | | | |
105+
| +-----------+ +--+------+ +----+----+ +---------+ +---+---+ +---------+ +---+---+ |
106+
| : ^ | : : |
107+
| | | | | | |
108+
| Compile time | | | | | |
109+
\------------------|---|---------|----------------------|---------------------|-----/
110+
| | | | |
111+
| | | /-----/ /-----------/
112+
| | | | |
113+
/----------/ \------+--|----------+-----|---------\ |
114+
| | | | | | |
115+
/-------|---------------------|--|----------|-----|---------|-----|-----------------\
116+
| | | | | | | | Runtime |
117+
| v : | : v : v |
118+
| +----------+ +-----+------+ +----+---------+ +---+--------+ |
119+
| |cGRE | |cYEL | |cYEL | |cYEL | |
120+
| |Log4j Core| |JPL to Log4j| |SLF4J to Log4j| |JUL to Log4j| |
121+
| | | | | | | | | |
122+
| +----------+ +------------+ +--------------+ +------------+ |
123+
| |log4j2.xml| ^ | |
124+
| +----------+ | | |
125+
| | | |
126+
| | | |
127+
| /-------------+--|--/ |
128+
| | | | |
129+
| +----------+-------------|--|---------------------------------------------------+ |
130+
| |JRE v : | |
131+
| | +----+--+ | |
132+
| | |{d}c1FF| | |
133+
| | | JPL | | |
134+
| | | | | |
135+
| | +-------+ | |
136+
| | | |
137+
| +-------------------------------------------------------------------------------+ |
138+
| |
139+
\-----------------------------------------------------------------------------------/
140+
....
141+
91142
[#requirements]
92143
== Requirements
93144
94145
The Log4j 2 runtime requires a minimum of Java {java-target-version}.
95-
See xref:index.adoc#older-releases[older releases] for the latest releases supporting Java 6 and 7.
146+
See xref:download.adoc#older[the Download page] for older releases supporting Java 6 and 7.
96147
97148
[#build-tool]
98149
== Configuring the build tool
@@ -195,8 +246,8 @@ Maven::
195246
[source,xml]
196247
----
197248
<dependency>
198-
<groupId>org.apache.logging.log4j</groupId>
199-
<artifactId>log4j-api</artifactId>
249+
<groupId>org.apache.logging.log4j</groupId>
250+
<artifactId>log4j-api</artifactId>
200251
</dependency>
201252
----
202253
@@ -215,6 +266,7 @@ Log4j provides several modules to facilitate deployment of different logging imp
215266
216267
`log4j-core`::
217268
The reference implementation.
269+
Log4 Core primarily accepts input from Log4j API.
218270
Refer to <<impl-core>> for the installation instructions.
219271
220272
`log4j-to-jul`::
@@ -269,12 +321,16 @@ Maven::
269321
[source,xml]
270322
----
271323
<dependencies>
272-
<dependency>
273-
<groupId>org.apache.logging.log4j</groupId>
274-
<artifactId>log4j-core</artifactId>
275-
<scope>runtime</scope>
276-
</dependency>
277-
<!-- Logging bridges will follow... -->
324+
325+
<!-- Logging implementation (Log4j Core) -->
326+
<dependency>
327+
<groupId>org.apache.logging.log4j</groupId>
328+
<artifactId>log4j-core</artifactId>
329+
<scope>runtime</scope>
330+
</dependency>
331+
332+
<!-- Logging bridges will follow... -->
333+
278334
</dependencies>
279335
----
280336
@@ -291,6 +347,17 @@ runtimeOnly 'org.apache.logging.log4j:log4j-core'
291347
==== Installing bridges
292348
293349
If either your application or one if its dependencies logs against a logging API that is different from Log4j API, you need to xref:#logging-bridge[bridge] that API to Log4j API.
350+
351+
[TIP]
352+
====
353+
**Do you need bridges?
354+
And if so, which ones?**
355+
356+
* If you have any direct or transitive dependency on `org.slf4j:slf4j-api`, you need xref:#impl-core-bridge-slf4j[the SLF4J-to-Log4j bridge].
357+
* If you have any direct or transitive dependency on `commons-logging:commons-logging`, you need xref:#impl-core-bridge-jcl[the JCL-to-Log4j bridge].
358+
* If it is a standalone application (i.e., not running in a Java EE container), you will probably need xref:#impl-core-bridge-jul[JUL-to-Log4j] and xref:#impl-core-bridge-jpl[JPL-to-Log4j] bridges.
359+
====
360+
294361
Following sections explain installation of Log4j-provided bridges.
295362
296363
[#impl-core-bridge-slf4j]
@@ -306,9 +373,9 @@ Maven::
306373
----
307374
<!-- SLF4J-to-Log4j bridge -->
308375
<dependency>
309-
<groupId>org.apache.logging.log4j</groupId>
310-
<artifactId>log4j-slf4j2-impl</artifactId>
311-
<scope>runtime</scope>
376+
<groupId>org.apache.logging.log4j</groupId>
377+
<artifactId>log4j-slf4j2-impl</artifactId>
378+
<scope>runtime</scope>
312379
</dependency>
313380
----
314381
@@ -333,9 +400,9 @@ Maven::
333400
----
334401
<!-- JUL-to-Log4j bridge -->
335402
<dependency>
336-
<groupId>org.apache.logging.log4j</groupId>
337-
<artifactId>log4j-jul</artifactId>
338-
<scope>runtime</scope>
403+
<groupId>org.apache.logging.log4j</groupId>
404+
<artifactId>log4j-jul</artifactId>
405+
<scope>runtime</scope>
339406
</dependency>
340407
----
341408
@@ -369,9 +436,9 @@ Maven::
369436
----
370437
<!-- JPL-to-Log4j bridge -->
371438
<dependency>
372-
<groupId>org.apache.logging.log4j</groupId>
373-
<artifactId>log4j-jpl</artifactId>
374-
<scope>runtime</scope>
439+
<groupId>org.apache.logging.log4j</groupId>
440+
<artifactId>log4j-jpl</artifactId>
441+
<scope>runtime</scope>
375442
</dependency>
376443
----
377444
@@ -399,11 +466,11 @@ Maven users should add an entry to the `<dependencyManagement>` section of their
399466
[source,xml,subs="+attributes"]
400467
----
401468
<dependencyManagement>
402-
<dependency>
403-
<groupId>commons-logging</groupId>
404-
<artifactId>commons-logging</artifactId>
405-
<version>{commons-logging-version}</version>
406-
</dependency>
469+
<dependency>
470+
<groupId>commons-logging</groupId>
471+
<artifactId>commons-logging</artifactId>
472+
<version>{commons-logging-version}</version>
473+
</dependency>
407474
</dependencyManagement>
408475
----
409476
@@ -431,21 +498,24 @@ Maven::
431498
[source,xml]
432499
----
433500
<dependencies>
434-
<dependency>
435-
<groupId>org.springframework.boot</groupId>
436-
<artifactId>spring-boot-starter</artifactId>
437-
<exclusions>
438-
<exclusion>
439-
<groupId>org.springframework.boot</groupId>
440-
<artifactId>spring-boot-starter-logging</artifactId>
441-
</exclusion>
442-
</exclusions>
443-
</dependency>
444-
<dependency>
501+
502+
<dependency>
503+
<groupId>org.springframework.boot</groupId>
504+
<artifactId>spring-boot-starter</artifactId>
505+
<exclusions>
506+
<exclusion>
445507
<groupId>org.springframework.boot</groupId>
446-
<artifactId>spring-boot-starter-log4j2</artifactId>
447-
<scope>runtime</scope>
448-
</dependency>
508+
<artifactId>spring-boot-starter-logging</artifactId>
509+
</exclusion>
510+
</exclusions>
511+
</dependency>
512+
513+
<dependency>
514+
<groupId>org.springframework.boot</groupId>
515+
<artifactId>spring-boot-starter-log4j2</artifactId>
516+
<scope>runtime</scope>
517+
</dependency>
518+
449519
</dependencies>
450520
----
451521
@@ -454,11 +524,11 @@ Gradle::
454524
[source,groovy]
455525
----
456526
configurations {
457-
all.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
527+
all.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
458528
}
459529
460530
dependencies {
461-
runtimeOnly group: 'org.springframework.boot', module: 'spring-boot-starter-log4j2'
531+
runtimeOnly group: 'org.springframework.boot', module: 'spring-boot-starter-log4j2'
462532
}
463533
----
464534
@@ -488,16 +558,19 @@ log4j2.xml::
488558
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
489559
xsi:schemaLocation="https://logging.apache.org/xml/ns
490560
https://logging.apache.org/xml/ns/log4j-config-2.xsd">
561+
491562
<appenders>
492563
<Console name="CONSOLE">
493564
<PatternLayout pattern="%d [%t] %5p %c{1.} - %m%n"/><!--1-->
494565
</Console>
495566
</appenders>
567+
496568
<loggers>
497569
<root level="INFO">
498570
<AppenderRef ref="CONSOLE"/>
499571
</root>
500-
</Loggers>
572+
</loggers>
573+
501574
</Configuration>
502575
----
503576
@@ -578,10 +651,10 @@ log4j2.json::
578651
[source,xml,subs="+attributes"]
579652
----
580653
<dependency>
581-
<groupId>com.fasterxml.jackson.core</groupId>
582-
<artifactId>jackson-databind</artifactId>
583-
<version>{jackson-version}</version>
584-
<scope>runtime</scope>
654+
<groupId>com.fasterxml.jackson.core</groupId>
655+
<artifactId>jackson-databind</artifactId>
656+
<version>{jackson-version}</version>
657+
<scope>runtime</scope>
585658
</dependency>
586659
----
587660
@@ -590,10 +663,10 @@ log4j2.yaml::
590663
[source,xml,subs="+attributes"]
591664
----
592665
<dependency>
593-
<groupId>com.fasterxml.jackson.dataformat</groupId>
594-
<artifactId>jackson-dataformat-yaml</artifactId>
595-
<version>{jackson-version}</version>
596-
<scope>runtime</scope>
666+
<groupId>com.fasterxml.jackson.dataformat</groupId>
667+
<artifactId>jackson-dataformat-yaml</artifactId>
668+
<version>{jackson-version}</version>
669+
<scope>runtime</scope>
597670
</dependency>
598671
----
599672
@@ -653,20 +726,24 @@ Maven::
653726
[source,xml,subs="+attributes"]
654727
----
655728
<dependencies>
729+
656730
<!-- Log4j-to-JUL bridge -->
657-
<dependency>
658-
<groupId>org.apache.logging.log4j</groupId>
659-
<artifactId>log4j-to-jul</artifactId>
660-
<scope>runtime</scope>
661-
</dependency>
662-
<!-- SLF4J-to-JUL bridge -->
663-
<dependency>
664-
<groupId>org.slf4j</groupId>
665-
<artifactId>slf4j-jdk14</artifactId>
666-
<version>{slf4j-version}</version>
667-
<scope>runtime</scope>
668-
</dependency>
669-
<!-- ... -->
731+
<dependency>
732+
<groupId>org.apache.logging.log4j</groupId>
733+
<artifactId>log4j-to-jul</artifactId>
734+
<scope>runtime</scope>
735+
</dependency>
736+
737+
<!-- SLF4J-to-JUL bridge -->
738+
<dependency>
739+
<groupId>org.slf4j</groupId>
740+
<artifactId>slf4j-jdk14</artifactId>
741+
<version>{slf4j-version}</version>
742+
<scope>runtime</scope>
743+
</dependency>
744+
745+
<!-- ... -->
746+
670747
</dependencies>
671748
----
672749
@@ -695,18 +772,22 @@ Maven::
695772
[source,xml]
696773
----
697774
<dependencies>
698-
<dependency>
699-
<groupId>ch.qos.logback</groupId>
700-
<artifactId>logback-classic</artifactId>
701-
<version>{logback-version}</version>
702-
<scope>runtime</scope>
703-
</dependency>
704-
<!-- Log4j-to-SLF4J bridge -->
705-
<dependency>
706-
<groupId>org.apache.logging.log4j</groupId>
707-
<artifactId>log4j-to-slf4j</artifactId>
708-
<scope>runtime</scope>
709-
</dependency>
775+
776+
<!-- Logging implementation (Logback) -->
777+
<dependency>
778+
<groupId>ch.qos.logback</groupId>
779+
<artifactId>logback-classic</artifactId>
780+
<version>{logback-version}</version>
781+
<scope>runtime</scope>
782+
</dependency>
783+
784+
<!-- Log4j-to-SLF4J bridge -->
785+
<dependency>
786+
<groupId>org.apache.logging.log4j</groupId>
787+
<artifactId>log4j-to-slf4j</artifactId>
788+
<scope>runtime</scope>
789+
</dependency>
790+
710791
</dependencies>
711792
----
712793

0 commit comments

Comments
 (0)
Please sign in to comment.