Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 2. Enabling JBoss Logging for your application
When you want to use JBoss Logging to collect application logs, you must add a logger to each class that you want to produce log. The following procedure demonstrates how you can add logging to your application programmatically using the API approach or declaratively using annotations.
Procedure
Depending on your application code, use one of the following approaches:
Create an instance of
org.jboss.logging.Loggerand initialize it by calling the static methodLogger.getLogger(Class)for each class:src/main/java/org/acme/ExampleResource.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Inject a configured
org.jboss.logging.Loggerinstance in your beans and resource classes:src/main/java/org/acme/ExampleResource.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Add the
org.jboss.logging.Loggerimport statement for each class namespace that you want to use. - 2
- The fully qualified class name of the declaring class is used as the logger name, which is equivalent to the initialization statement
org.jboss.logging.Logger.getLogger(ExampleResource.class). - 3
- Set a name for the logger. In this example, the logger name is foo, which is equivalent to the initialization statement
org.jboss.logging.Logger.getLogger("foo").
NoteThe logger instances are cached internally. A logger, that you inject into a bean, is shared for all bean instances to avoid the possible performance penalty associated with logger instantiation.
(Optional) Configure the logging output in your
application.propertiesfile:src/main/resources/application.properties
<configuration_key>=<value>
<configuration_key>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example, you can create a log file and print the output to a console and to the file:
src/main/resources/application.properties
quarkus.log.file.enable=true quarkus.log.file.path=/tmp/trace.log
quarkus.log.file.enable=true quarkus.log.file.path=/tmp/trace.logCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run your application in development mode:
./mvnw quarkus:dev
./mvnw quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Navigate to
http://localhost:8080/hello. Depending on your configuration, review the log messages on your terminal or in your log file.
Example output for the
ExampleResource.classwith logging level set toINFO:2021-05-21 15:38:39,751 INFO [io.quarkus] (Quarkus Main Thread) my-project my-version on JVM (powered by Quarkus 1.13.3.Final) started in 1.189s. Listening on: http://localhost:8080 2021-05-21 15:38:39,765 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated. 2021-05-21 15:38:39,766 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy] 2021-05-21 15:38:58,790 INFO [ExampleResource] (executor-thread-1) Hello
2021-05-21 15:38:39,751 INFO [io.quarkus] (Quarkus Main Thread) my-project my-version on JVM (powered by Quarkus 1.13.3.Final) started in 1.189s. Listening on: http://localhost:8080 2021-05-21 15:38:39,765 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated. 2021-05-21 15:38:39,766 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy] 2021-05-21 15:38:58,790 INFO [ExampleResource] (executor-thread-1) HelloCopy to Clipboard Copied! Toggle word wrap Toggle overflow