From 27721650a908f0632c93f1380c5618829363a2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Wed, 8 Jul 2020 18:29:31 +0200 Subject: [PATCH 1/3] Using Log4j2 --- docs/src/main/asciidoc/logging.adoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/src/main/asciidoc/logging.adoc b/docs/src/main/asciidoc/logging.adoc index 29555c286e86c..9c87e8938aa90 100644 --- a/docs/src/main/asciidoc/logging.adoc +++ b/docs/src/main/asciidoc/logging.adoc @@ -209,6 +209,19 @@ Applications and components may use any of the following APIs for logging, and t * https://www.slf4j.org/[SLF4J] * https://commons.apache.org/proper/commons-logging/[Apache Commons Logging] +If you want to use log4j2, you need to use the `log4j2-jboss-logmanager` to route log4j2 logs to `jboss-logmanager`. + +You will then be able to use the log4j2 API inside your code and configure your logger via your `application.properties`. + +[code,xml] +---- + + org.jboss.logmanager + log4j2-jboss-logmanager + +---- + +WARNING: do not include any log4j2 dependencies, the `log4j2-jboss-logmanager` library include what's needed to use log4j2. + == Centralized Log Management If you want to send your logs to a centralized tool like Graylog, Logstash or Fluentd, you can follow the link:centralized-log-management[Centralized log management guide]. From 1671b8aa56f78020344ddb1a3503a689801969ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 21 Jul 2020 15:33:07 +0200 Subject: [PATCH 2/3] Improve logging guide --- .../io/quarkus/runtime/logging/LogConfig.java | 20 ++- docs/src/main/asciidoc/logging.adoc | 170 +++++++++++++----- 2 files changed, 140 insertions(+), 50 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java index 1e5a257ee0d42..a32aa18da40c4 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/LogConfig.java @@ -17,23 +17,29 @@ public final class LogConfig { /** * The log level of the root category, which is used as the default log level for all categories. * - * In addition to the standard JDK log level JBoss Logging also adds the following: + * JBoss Logging supports Apache style log levels: * - * {@link org.jboss.logmanager.Level#FATAL} - * {@link org.jboss.logmanager.Level#ERROR} - * {@link org.jboss.logmanager.Level#WARN} - * {@link org.jboss.logmanager.Level#INFO} - * {@link org.jboss.logmanager.Level#DEBUG} - * {@link org.jboss.logmanager.Level#TRACE} + * * {@link org.jboss.logmanager.Level#FATAL} + * * {@link org.jboss.logmanager.Level#ERROR} + * * {@link org.jboss.logmanager.Level#WARN} + * * {@link org.jboss.logmanager.Level#INFO} + * * {@link org.jboss.logmanager.Level#DEBUG} + * * {@link org.jboss.logmanager.Level#TRACE} * + * In addition, it also supports the standard JDK log levels. + * + * @asciidoclet */ @ConfigItem(defaultValue = "INFO") public Level level; /** * The default minimum log level + * + * @deprecated this functionality was never implemented, it may be deleted or implemented in a future release. */ @ConfigItem(defaultValue = "INFO") + @Deprecated public Level minLevel; /** diff --git a/docs/src/main/asciidoc/logging.adoc b/docs/src/main/asciidoc/logging.adoc index 9c87e8938aa90..32a32cec44380 100644 --- a/docs/src/main/asciidoc/logging.adoc +++ b/docs/src/main/asciidoc/logging.adoc @@ -9,10 +9,95 @@ include::./attributes.adoc[] This guide explains logging and how to configure it. +Internally, Quarkus uses JBoss Log Manager and the JBoss Logging facade. + +You can use the JBoss Logging facade inside your code as it's already provided, +or any of the supported Logging API listed in the next chapter as Quarkus will send them to JBoss Log Manager. + +All the logging configuration will then be done inside your `application.properties`. + +== Supported Logging APIs + +Applications and components may use any of the following APIs for logging, and the logs will be merged: + +* JDK `java.util.logging` (also called JUL) +* https://github.com/jboss-logging/jboss-logging[JBoss Logging] +* https://www.slf4j.org/[SLF4J] +* https://commons.apache.org/proper/commons-logging/[Apache Commons Logging] + +Internally Quarkus uses JBoss Logging; you can also use it inside your application so that no other dependencies should be added for your logs. + +[source,java] +---- +import org.jboss.logging.Logger; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class ExampleResource { + + private static final Logger LOG = Logger.getLogger(ExampleResource.class); + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + LOG.info("Hello"); + return "hello"; + } +} +---- + +NOTE: If you use JBoss Logging but one of your libraries uses a different logging API, you may need to configure a link:#logging-adapters[Logging Adapter]. + +=== What about Apache Log4j ? + +link:https://logging.apache.org/log4j/2.x/[Log4j] is a logging implementation: it contains a logging backend and a logging facade. +Quarkus uses the JBoss Log Manager backend, so you will need to include the `log4j2-jboss-logmanager` library to route Log4j logs to JBoss Log Manager. + +[source,xml] +---- + + org.jboss.logmanager + log4j2-jboss-logmanager <1> + +---- + +<1> This is the library needed for Log2J version 2; if you use the legacy Log4J version 1 you need to use `log4j-jboss-logmanager` instead. + +You can then use the Log4J API inside your application. + +WARNING: Do not include any Log4j dependencies. The `log4j2-jboss-logmanager` library includes what's needed to use Log4j as a logging facade. + +== Logging levels + +These are the log levels used by Quarkus: + +[horizontal] +OFF:: Special level to turn off logging. +FATAL:: A critical service failure/complete inability to service requests of any kind. +ERROR:: A significant disruption in a request or the inability to service a request. +WARN:: A non-critical service error or problem that may not require immediate correction. +INFO:: Service lifecycle events or important related very-low-frequency information. +DEBUG:: Messages that convey extra information regarding lifecycle or non-request-bound events which may be helpful for debugging. +TRACE:: Messages that convey extra per-request debugging information that may be very high frequency. +ALL:: Special level for all messages including custom levels. + +In addition, the following levels may be configured for applications and libraries using link:https://docs.oracle.com/javase/8/docs/api/java/util/logging/Level.html[`java.util.logging`]: + +[horizontal] +SEVERE:: Same as **ERROR**. +WARNING:: Same as **WARN**. +CONFIG:: Service configuration information. +FINE:: Same as **DEBUG**. +FINER:: Same as **TRACE**. +FINEST:: Event more debugging information than `TRACE`, maybe with even higher frequency. + == Runtime configuration Run time logging is configured in the `application.properties` file, -for example to set everything to `INFO` logging except Hibernate: +for example, to set the default log level to `INFO` logging and include Hibernate `DEBUG` logs: [source, properties] ---- @@ -54,23 +139,14 @@ The root logger category is handled separately, and is configured via the follow |quarkus.log.level|INFO|The default minimum log level for every log category. |=== -=== Log levels +If no level configuration exists for a given logger category, the enclosing (parent) category is examined. If no categories are configured which enclose the category in question, then the root logger configuration is used. -There are several log levels you can use: +== Logging Format -[cols=" - org.jboss.logmanager - log4j2-jboss-logmanager - ----- - -WARNING: do not include any log4j2 dependencies, the `log4j2-jboss-logmanager` library include what's needed to use log4j2. - == Centralized Log Management If you want to send your logs to a centralized tool like Graylog, Logstash or Fluentd, you can follow the link:centralized-log-management[Centralized log management guide]. @@ -278,7 +360,7 @@ This is especially important when building native executables as you could encou Caused by java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl ---- -This is due to the logging implementation not being embarked in the the native executable. +This is due to the logging implementation not being included in the native executable. Using the JBoss Logging adapters will solve this problem. These adapters are available for most of the common Open Source logging components, such as Apache Commons Logging: @@ -331,6 +413,8 @@ And Slf4j: ---- +NOTE: This is not needed for libraries that are dependencies of a Quarkus extension as the extension will take care of this for you. + [[loggingConfigurationReference]] == Logging configuration reference From 9d8117c8dbd61c44eb9ed9c49b261e987dd4cfc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 21 Jul 2020 10:07:55 +0200 Subject: [PATCH 3/3] Add log4j-jboss-logmanager to the bom --- bom/application/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 6f6d244aca926..96cdf0c925ae2 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -200,6 +200,7 @@ 2.8.6 0.46 1.0.0.Beta1 + 1.2.0.Final 1.10.0 @@ -1971,6 +1972,11 @@ log4j2-jboss-logmanager ${log4j2-jboss-logmanager.version} + + org.jboss.logmanager + log4j-jboss-logmanager + ${log4j-jboss-logmanager.version} + io.quarkus.gizmo