이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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

  1. Depending on your application code, use one of the following approaches:

    1. Create an instance of org.jboss.logging.Logger and initialize it by calling the static method Logger.getLogger(Class) for each class:

      src/main/java/org/acme/ExampleResource.java

      import org.jboss.logging.Logger; 
      1
      
      
      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); 
      2
      
      
          @GET
          @Produces(MediaType.TEXT_PLAIN)
          public String hello() {
              LOG.info("Hello"); 
      3
      
              return "hello";
          }
      }

      1
      Add the org.jboss.logging.Logger import statement for each class namespace that you want to use.
      2
      Add reference to the logger singleton for each class.
      3
      Set a logging level for the log message.
    2. Inject a configured org.jboss.logging.Logger instance in your beans and resource classes:

      src/main/java/org/acme/ExampleResource.java

      import javax.inject.Inject;
      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;
      
      import org.jboss.logging.Logger; 
      1
      
      
      import io.quarkus.arc.log.LoggerName;
      
      @Path("/hello")
      public class ExampleResource {
      
          @Inject
          Logger log; 
      2
      
      
          @LoggerName("foo")
          Logger fooLog; 
      3
      
      
          @GET
          @Produces(MediaType.TEXT_PLAIN)
          public String hello() {
              log.info("Simple!");
              fooLog.info("Goes to foo logger!");
              return "hello";
          }
      }

      1
      Add the org.jboss.logging.Logger import 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").
      Note

      The 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.

  2. (Optional) Configure the logging output in your application.properties file:

    src/main/resources/application.properties

    <configuration_key>=<value>

    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

  3. Run your application in development mode:

    ./mvnw quarkus:dev
  4. Navigate to http://localhost:8080/hello.
  5. Depending on your configuration, review the log messages on your terminal or in your log file.

    Example output for the ExampleResource.class with logging level set to INFO:

    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
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동