Skip to content

Commit 706da86

Browse files
committed
Improve Logging guide regarding logging adapters
We had several complaints that it was hard to notice people would use their favorite logging API so I made it a lot more explicit. Also I made the APIs titles so that they could be included in the TOC.
1 parent e1608f9 commit 706da86

File tree

1 file changed

+64
-35
lines changed

1 file changed

+64
-35
lines changed

docs/src/main/asciidoc/logging.adoc

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,40 @@ include::_attributes.adoc[]
99
:categories: core,getting-started,observability
1010
:diataxis-type: reference
1111
:topics: logging,observability
12+
:toclevels: 4
1213

1314
Read about the use of logging API in {project-name}, configuring logging output, and using logging adapters to unify the output from other logging APIs.
1415

1516
include::{includes}/observability-include.adoc[]
1617

1718
Quarkus uses the JBoss Log Manager logging backend for publishing application and framework logs.
1819
Quarkus supports the JBoss Logging API and multiple other logging APIs, seamlessly integrated with JBoss Log Manager.
19-
You can use any of the <<logging-apis,following APIs>>:
2020

21-
* link:https://github.com/jboss-logging/jboss-logging[JBoss Logging]
22-
* link:https://docs.oracle.com/en/java/javase/17/docs/api/java.logging/java/util/logging/package-summary.html[JDK `java.util.logging` (JUL)]
23-
* link:https://www.slf4j.org/[SLF4J]
24-
* link:https://commons.apache.org/proper/commons-logging/[Apache Commons Logging]
25-
* link:https://logging.apache.org/log4j/2.x/[Apache Log4j 2]
26-
* link:https://logging.apache.org/log4j/1.2/[Apache Log4j 1]
21+
This means you can use your favorite logging API with Quarkus, providing you add the <<logging-apis,appropriate adapter>> to your application:
22+
23+
[cols="2,1", options="header"]
24+
|===
25+
| Logging API
26+
| Adapter
27+
28+
| link:https://github.com/jboss-logging/jboss-logging[JBoss Logging]
29+
| Built-in
30+
31+
| link:https://docs.oracle.com/en/java/javase/17/docs/api/java.logging/java/util/logging/package-summary.html[JDK `java.util.logging` (JUL)]
32+
| Built-in
33+
34+
| link:https://www.slf4j.org/[SLF4J]
35+
| <<logging-adapters-slf4j,SLF4J adapter>>
36+
37+
| link:https://commons.apache.org/proper/commons-logging/[Apache Commons Logging]
38+
| <<logging-adapters-commons-logging,Commons Logging adapter>>
39+
40+
| link:https://logging.apache.org/log4j/2.x/[Apache Log4j 2]
41+
| <<logging-adapters-log4j2,Log4j 2 adapter>>
42+
43+
| link:https://logging.apache.org/log4j/1.2/[Apache Log4j 1]
44+
| <<logging-adapters-log4j,Log4j 1 adapter>>
45+
|===
2746

2847
[[jboss-logging]]
2948
== Use JBoss Logging for application logging
@@ -765,50 +784,59 @@ The logging implementation is not included in the native executable, but you can
765784

766785
These adapters are available for popular open-source logging components, as explained in the next chapter.
767786

787+
[[logging-adapters]]
768788
=== Add a logging adapter to your application
769789

770-
For each logging API that is not `jboss-logging`:
790+
For each logging API that is not JBoss Logging, add a logging adapter library to ensure that messages logged through these APIs are routed to the JBoss Log Manager backend.
791+
You can then verify whether the logs generated by the added library adhere to the same format as the other Quarkus logs.
771792

772-
. Add a logging adapter library to ensure that messages logged through these APIs are routed to the JBoss Log Manager backend.
773-
+
774793
NOTE: This step is unnecessary for libraries that are dependencies of a Quarkus extension where the extension handles it automatically.
775-
+
776-
* Apache Commons Logging:
777-
+
794+
795+
[[logging-adapters-slf4j]]
796+
==== SLF4J
797+
798+
The SLF4J adapter is provided by the following dependency:
799+
778800
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
779801
.pom.xml
780802
----
781803
<dependency>
782-
<groupId>org.jboss.logging</groupId>
783-
<artifactId>commons-logging-jboss-logging</artifactId>
804+
<groupId>org.jboss.slf4j</groupId>
805+
<artifactId>slf4j-jboss-logmanager</artifactId>
784806
</dependency>
785807
----
786-
+
808+
787809
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
788810
.build.gradle
789811
----
790-
implementation("org.jboss.logging:commons-logging-jboss-logging")
812+
implementation("org.jboss.slf4j:slf4j-jboss-logmanager")
791813
----
792814

793-
* Log4j:
794-
+
815+
[[logging-adapters-commons-logging]]
816+
==== Apache Commons Logging
817+
818+
The Commons Logging adapter is provided by the following dependency:
819+
795820
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
796821
.pom.xml
797822
----
798823
<dependency>
799-
<groupId>org.jboss.logmanager</groupId>
800-
<artifactId>log4j-jboss-logmanager</artifactId>
824+
<groupId>org.jboss.logging</groupId>
825+
<artifactId>commons-logging-jboss-logging</artifactId>
801826
</dependency>
802827
----
803-
+
828+
804829
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
805830
.build.gradle
806831
----
807-
implementation("org.jboss.logmanager:log4j-jboss-logmanager")
832+
implementation("org.jboss.logging:commons-logging-jboss-logging")
808833
----
809834

810-
* Log4j 2:
811-
+
835+
[[logging-adapters-log4j2]]
836+
==== Log4j 2
837+
838+
The Log4j 2 adapter is provided by the following dependency:
839+
812840
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
813841
.pom.xml
814842
----
@@ -817,37 +845,38 @@ implementation("org.jboss.logmanager:log4j-jboss-logmanager")
817845
<artifactId>log4j2-jboss-logmanager</artifactId>
818846
</dependency>
819847
----
820-
+
848+
821849
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
822850
.build.gradle
823851
----
824852
implementation("org.jboss.logmanager:log4j2-jboss-logmanager")
825853
----
826-
+
854+
827855
[NOTE]
828856
====
829857
Do not include any Log4j dependencies, as the `log4j2-jboss-logmanager` library contains everything needed to use Log4j as a logging implementation.
830858
====
831859

832-
* SLF4J:
833-
+
860+
[[logging-adapters-log4j]]
861+
==== Log4j
862+
863+
The Log4j adapter is provided by the following dependency:
864+
834865
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
835866
.pom.xml
836867
----
837868
<dependency>
838-
<groupId>org.jboss.slf4j</groupId>
839-
<artifactId>slf4j-jboss-logmanager</artifactId>
869+
<groupId>org.jboss.logmanager</groupId>
870+
<artifactId>log4j-jboss-logmanager</artifactId>
840871
</dependency>
841872
----
842-
+
873+
843874
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
844875
.build.gradle
845876
----
846-
implementation("org.jboss.slf4j:slf4j-jboss-logmanager")
877+
implementation("org.jboss.logmanager:log4j-jboss-logmanager")
847878
----
848879

849-
. Verify whether the logs generated by the added library adhere to the same format as the other Quarkus logs.
850-
851880
=== Use MDC to add contextual log information
852881

853882
Quarkus overrides the logging Mapped Diagnostic Context (MDC) to improve compatibility with its reactive core.

0 commit comments

Comments
 (0)