The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

ロギングの設定

このガイドでは、ロギングとその設定方法について説明します。

内部的には、QuarkusはJBoss Log ManagerとJBoss Logging ファサードを使用します。 JBoss Logging ファサードはすでに提供されているので、コード内部で使用することができますが、QuarkusがJBoss Log Managerに送信するため、次の章でリストアップされているサポートされたロギングAPIのいずれかを使用することもできます。

すべてのロギング設定は、 application.properties の中で実施されます。

サポートされているロギング API

アプリケーションやコンポーネントは、以下のいずれかのAPIを使用してログを出力することができ、ログはマージされます。

Quarkusは内部的にJBoss Loggingを使用しています。アプリケーションの内部で使用することもできるので、ログに他の依存関係を追加する必要はありません。

import org.jboss.logging.Logger;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.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";
    }
}
JBoss Logging を使用しているが、ライブラリの 1 つが異なるロギング API を使用している場合、 ロギングアダプター を構成する必要がある場合があります。

Logging with Panache

Logger フィールドを宣言する代わりに、簡略化されたロギング API を使用することができます。

package com.example;

import io.quarkus.logging.Log; (1)

class MyService { (2)
    public void doSomething() {
        Log.info("Simple!"); (3)
    }
}
1 io.quarkus.logging.Log クラスは、すべてのメソッドが static であることを除き、JBoss Logging API をミラーリングします。
2 なお、このクラスではloggerフィールドを宣言していません。これは、アプリケーションのビルド時に、 Log API を使用する各クラスに private static final org.jboss.logging.Logger フィールドが自動的に作成されるためです。 Log メソッドを呼び出したクラスの完全修飾名がロガー名として使用されます。この例では、ロガー名は com.example.MyService となります。
3 最後に、アプリケーションのビルド時に、 Log メソッドへのすべての呼び出しが、logger フィールド上の通常の JBoss Logging 呼び出しに書き換えられます。
Log APIはアプリケーションクラスでのみ使用し、外部の依存関係では使用しないでください。ビルド時にQuarkusによって処理されていない Log メソッド呼び出しは、例外が発生します。

Loggerの挿入

また、設定済みの org.jboss.logging.Logger インスタンスを Bean やリソースクラスに注入することもできます。

import org.jboss.logging.Logger;

@ApplicationScoped
class SimpleBean {

   @Inject
   Logger log; (1)

   @LoggerName("foo")
   Logger fooLog; (2)

   public void ping() {
     log.info("Simple!");
     fooLog.info("Goes to _foo_ logger!");
   }
}
1 org.jboss.logging.Logger.getLogger(SimpleBean.class) 宣言したクラスのFQCNがロガー名として使用されます。
2 org.jboss.logging.Logger.getLogger("foo") この場合、ロガー名として foo という名前が使われます。
ロガーインスタンスは内部的にキャッシュされます。したがって、例えば @RequestScoped Bean に注入されたロガーは、ロガーのインスタンス化に関連する可能性のあるパフォーマンスのペナルティを回避するために、すべての Bean インスタンスで共有されます。

Apache Log4j はどうですか?

Log4j はロギングの実装の一つです: ロギングバックエンドとロギングファサードが含まれています。QuarkusはJBoss Log Managerバックエンドを使用するため、Log4jログをJBoss Log Managerにルーティングするためには log4j2-jboss-logmanager ライブラリをインクルードする必要があります。

pom.xml
<dependency>
    <groupId>org.jboss.logmanager</groupId>
    <artifactId>log4j2-jboss-logmanager</artifactId> (1)
</dependency>
1 これはLog4Jのバージョン2に必要なライブラリです。もしレガシーなLog4Jのバージョン1を使用している場合は、代わりに log4j-jboss-logmanager を使用する必要があります。
build.gradle
implementation("org.jboss.logmanager:log4j2-jboss-logmanager") (1)
1 これはLog4Jのバージョン2に必要なライブラリです。もしレガシーなLog4Jのバージョン1を使用している場合は、代わりに log4j-jboss-logmanager を使用する必要があります。

これで、アプリケーション内でLog4J APIを使用することができます。

Log4jの依存関係を含めないでください。 log4j2-jboss-logmanager ライブラリは、Log4j をロギング・ファサードとして使用するために必要なものを含んでいます。

ログレベル

これらはQuarkusで使用されているログレベルです。

OFF

ロギングをオフにするための特別なレベル

FATAL

致命的なサービス障害/いかなる種類のサービス要求にも完全に対応できないこと

ERROR

リクエストの大幅な中断、またはリクエストに対応できないこと

WARN

重要ではないサービスのエラーや問題で、すぐに修正する必要がない場合があります

INFO

サービスのライフサイクルイベントまたは重要な関連する非常に低頻度の情報

DEBUG

デバッグに役立つかもしれない、ライフサイクルまたは非リクエストバウンドイベントに関する余分な情報を伝えるメッセージ

TRACE

リクエストごとのデバッグ情報を伝えるメッセージで、非常に高い頻度で送信される可能性があります

ALL

カスタムレベルを含むすべてのメッセージのための特別なレベル

加えて、 java.util.logging を利用して、アプリケーションとライブラリに対して以下のレベルを設定することができます。

SEVERE

ERROR と同じ

WARNING

WARN と同じ

CONFIG

サービス構成情報

FINE

DEBUG と同じ

FINER

TRACE と同じ

FINEST

イベント TRACE よりも多くのデバッグ情報、さらに高頻度である可能性があります

実行時設定

実行時ロギングは application.properties ファイルで設定します。例えばデフォルトのログレベルを INFO ロギングに設定し、Hibernate の DEBUG ログを含めるようにします。

quarkus.log.level=INFO
quarkus.log.category."org.hibernate".level=DEBUG

ログレベルを DEBUG より下に設定するには、ログレベル自体を調整するだけでなく、グローバルに quarkus.log.min-level プロパティーを介して、または上記の例のようにカテゴリごとに、最小ログレベルを調整する必要があります。

最小ロギングレベルは、Quarkusが潜在的に生成するために必要となるフロアレベルを設定し、最適化の機会の扉を開きます。例えば、ネイティブ実行では、最小レベルを設定することで、低レベルのチェック(例: isTraceEnabled )を false に折りたたむことができ、結果として、実行されることのないコードのデッドコードを排除することができます。

ありうるすべてのプロパティは、 ロギング設定リファレンス セクションに記載されています。

コマンドラインを使用してこれらのプロパティを追加する場合、 " がエスケープされていることを確認してください。例えば、 -Dquarkus.log.category.\"org.hibernate\".level=TRACE となります。

ロギングカテゴリ

ログの記録はカテゴリーごとに行われます。各カテゴリは独立して設定することができます。あるカテゴリーに適用される設定は、そのカテゴリーのすべてのサブカテゴリーにも適用されますが、より具体的に一致するサブカテゴリーの設定がある場合は除きます。各カテゴリーには、(console/file/syslog)で設定されたものと同じ設定が適用されます。これらは、1つまたは複数の名前付きハンドラをカテゴリにアタッチすることで上書きすることもできます。 カテゴリーに付けられた名前付きハンドラ の出力例を参照してください。

プロパティ名e デフォルト 説明

quarkus.log.category."<category-name>".level

INFO [1]

<category-name> という名前のカテゴリを設定するために使用するレベル。クオートが必要です。

quarkus.log.category."<category-name>".min-level

DEBUG

<category-name> という名前のカテゴリを設定するために使用する最小ロギングレベル。クオートが必要です。

quarkus.log.category."<category-name>".use-parent-handlers

true

このロガーがその出力を親ロガーに送信するかどうかを指定します。

quarkus.log.category."<category-name>".handlers=[<handler>]

empty [2]

特定のカテゴリにアタッチしたいハンドラーの名前です。

プロパティ名に表示される引用符は、通常カテゴリが'.'を含むため、エスケープする必要があります。 File TRACE ロギング設定 の例を参照してください。

ルートロガーの設定

ルート ロガー カテゴリは個別に処理され、次のプロパティーで設定されます。

プロパティ名e デフォルト 説明

quarkus.log.level

INFO

各ログカテゴリのデフォルトのログレベル。

quarkus.log.min-level

DEBUG

各ログカテゴリのデフォルトの最小ログレベル。

与えられたロガー カテゴリにレベル設定が存在しない場合、包含(親)カテゴリが検査されます。対象のカテゴリを囲むカテゴリが設定されていない場合、ルート ロガー設定が使用されます。

ログフォーマット

デフォルトでは、Quarkusはパターンベースのログフォーマッタを使用して、人間が読めるテキストログを生成します。

各ログハンドラーのフォーマットは、専用のプロパティーで設定することができます。コンソールハンドラーの場合、プロパティーは quarkus.log.console.format です。

ログフォーマット文字列は、以下のシンボルをサポートしています。

Symbol 概要 説明

%%

%

単に % 文字をレンダリングします。

%c

カテゴリ

カテゴリ名をレンダリングします。

%C

ソースクラスs

ソースクラス名をレンダリングします。 [3]

d{xxx}.

Date

java.text.SimpleDateFormat で定義されている構文を使用した、指定した日付書式の文字列で日付をレンダリングします。

%e

Exception

投げられた例外があれば、その例外をレンダリングします。

%F

ソースファイルe

ソースファイル名をレンダリングします。 [3]

%h

ホスト名e

システムの単純なホスト名をレンダリングします。

%H

完全修飾ホスト名e

システムの完全修飾されたホスト名をレンダリングします。OSの設定によっては、単純ホスト名と同じかもしれません。

%i

プロセスID

現在のプロセスPIDをレンダリングします。

%l

ソースの場所

ソースファイル名、行番号、クラス名、メソッド名を含むソース・ロケーション情報をレンダリングします。 [3]

%L

ソースラインe

ソース行番号をレンダリングします。 [3]

%m

フルメッセージe

ログメッセージと例外(もしあれば)を表示します。

%M

ソースメソッドd

ソースメソッド名をレンダリングします。 [3]

%n

改行e

プラットフォーム固有の改行文字列をレンダリングします。

%N

プロセス名e

現在のプロセスの名前をレンダリングします。

%p

レベルl

メッセージのログレベルをレンダリングします。

%r

相対時間e

アプリケーションログの開始からの時間をミリ秒単位でレンダリングします。

%s

シンプルメッセージe

ログメッセージのみを表示し、例外のトレースは表示しません。

%t

スレッド名e

スレッド名をレンダリングします。

%t{id}

スレッドID

スレッドIDをレンダリングします。

%z{<zone name>}

タイムゾーンe

出力のタイムゾーンを <zone name> に設定します。

%X{<MDC property name>}

マップされた診断コンテキスト値e

マップされた診断コンテキストの値をレンダリングします。

%X

マップされた診断コンテキスト値s

マップされた診断コンテキストのすべての値を {property.key=property.value} 形式でレンダリングします。

%x

入れ子になった診断コンテキスト値s

ネストされた診断コンテキストからのすべての値を {value1.value2} 形式でレンダリングします。

コンソールログの代替フォーマット

コンソールログの出力形式を変更することができます。これは、Quarkusアプリケーションの出力がサービスによってキャプチャされ、例えば、後で分析するためにログ情報を処理して保存することができる環境で有用です。

JSON ログフォーマット

JSON ログフォーマットを設定するために、 quarkus-logging-json エクステンションモジュールを使用することができます。次のスニペットが示すように、このエクステンションをアプリケーションPOMに追加してください。

pom.xml
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-logging-json</artifactId>
</dependency>
build.gradle
implementation("io.quarkus:quarkus-logging-json")

このエクステンションがあると、デフォルトでは、コンソール設定の出力フォーマットの設定を置き換えることになります。つまり、フォーマット文字列と色の設定(もしあれば)は無視されます。非同期ロギングやログレベルを制御する項目を含む、他のコンソール設定項目は引き続き適用されます。

いくつかの場合、開発モードでは人間が読める(構造化されていない)ロギングを使用し、本番モードではJSONロギング(構造化されている)を使用することが理にかなっているでしょう。これは、以下の設定で示されているように、異なるプロファイルを使用して達成することができます。

application.properties で dev および test モードに対する JSONロギングを無効にする
%dev.quarkus.log.console.json=false
%test.quarkus.log.console.json=false
設定

JSON ロギングエクステンションは、さまざまな方法で設定することができます。以下のプロパティーがサポートされています。

ビルド時に固定される設定プロパティ - その他の設定プロパティは実行時にオーバーライド可能です。

Console logging

デフォルト

Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting.

Environment variable: QUARKUS_LOG_CONSOLE_JSON

boolean

true

Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read pretty printed output.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_PRETTY_PRINT

boolean

false

The date format to use. The special string "default" indicates that the default format should be used.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_DATE_FORMAT

string

default

The special end-of-record delimiter to be used. By default, newline is used as delimiter.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_RECORD_DELIMITER

string

The zone ID to use. The special string "default" indicates that the default zone should be used.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_ZONE_ID

string

default

The exception output type to specify.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_EXCEPTION_OUTPUT_TYPE

detailed, formatted, detailed-and-formatted

detailed

Enable printing of more details in the log. Printing the details can be expensive as the values are retrieved from the caller. The details include the source class name, source file name, source method name and source line number.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_PRINT_DETAILS

boolean

false

Override keys with custom values. Omitting this value indicates that no key overrides will be applied.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_KEY_OVERRIDES

string

Keys to be excluded from the Json output.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_EXCLUDED_KEYS

list of string

Additional field value.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_ADDITIONAL_FIELD__FIELD_NAME__VALUE

string

required

Additional field type specification. Supported types: string, int, long String is the default if not specified.

Environment variable: QUARKUS_LOG_CONSOLE_JSON_ADDITIONAL_FIELD__FIELD_NAME__TYPE

string, int, long

string

File logging

デフォルト

Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting.

Environment variable: QUARKUS_LOG_FILE_JSON

boolean

true

Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read pretty printed output.

Environment variable: QUARKUS_LOG_FILE_JSON_PRETTY_PRINT

boolean

false

The date format to use. The special string "default" indicates that the default format should be used.

Environment variable: QUARKUS_LOG_FILE_JSON_DATE_FORMAT

string

default

The special end-of-record delimiter to be used. By default, newline is used as delimiter.

Environment variable: QUARKUS_LOG_FILE_JSON_RECORD_DELIMITER

string

The zone ID to use. The special string "default" indicates that the default zone should be used.

Environment variable: QUARKUS_LOG_FILE_JSON_ZONE_ID

string

default

The exception output type to specify.

Environment variable: QUARKUS_LOG_FILE_JSON_EXCEPTION_OUTPUT_TYPE

detailed, formatted, detailed-and-formatted

detailed

Enable printing of more details in the log. Printing the details can be expensive as the values are retrieved from the caller. The details include the source class name, source file name, source method name and source line number.

Environment variable: QUARKUS_LOG_FILE_JSON_PRINT_DETAILS

boolean

false

Override keys with custom values. Omitting this value indicates that no key overrides will be applied.

Environment variable: QUARKUS_LOG_FILE_JSON_KEY_OVERRIDES

string

Keys to be excluded from the Json output.

Environment variable: QUARKUS_LOG_FILE_JSON_EXCLUDED_KEYS

list of string

Additional field value.

Environment variable: QUARKUS_LOG_FILE_JSON_ADDITIONAL_FIELD__FIELD_NAME__VALUE

string

required

Additional field type specification. Supported types: string, int, long String is the default if not specified.

Environment variable: QUARKUS_LOG_FILE_JSON_ADDITIONAL_FIELD__FIELD_NAME__TYPE

string, int, long

string

Syslog logging

デフォルト

Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting.

Environment variable: QUARKUS_LOG_SYSLOG_JSON

boolean

true

Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read pretty printed output.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_PRETTY_PRINT

boolean

false

The date format to use. The special string "default" indicates that the default format should be used.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_DATE_FORMAT

string

default

The special end-of-record delimiter to be used. By default, newline is used as delimiter.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_RECORD_DELIMITER

string

The zone ID to use. The special string "default" indicates that the default zone should be used.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_ZONE_ID

string

default

The exception output type to specify.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_EXCEPTION_OUTPUT_TYPE

detailed, formatted, detailed-and-formatted

detailed

Enable printing of more details in the log. Printing the details can be expensive as the values are retrieved from the caller. The details include the source class name, source file name, source method name and source line number.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_PRINT_DETAILS

boolean

false

Override keys with custom values. Omitting this value indicates that no key overrides will be applied.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_KEY_OVERRIDES

string

Keys to be excluded from the Json output.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_EXCLUDED_KEYS

list of string

Additional field value.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_ADDITIONAL_FIELD__FIELD_NAME__VALUE

string

required

Additional field type specification. Supported types: string, int, long String is the default if not specified.

Environment variable: QUARKUS_LOG_SYSLOG_JSON_ADDITIONAL_FIELD__FIELD_NAME__TYPE

string, int, long

string

プリティプリント (pretty printing) を有効にすると、特定のプロセッサーやJSONパーサーで解釈できなくなる可能性があります。
詳細の表示は、呼び出し元から値を取得するため、コストがかかる場合があります。詳細には、ソースクラス名、ソースファイル名、ソースメソッド名、ソース行番号などが含まれます。

ログハンドラー

ログハンドラーは、受信者へのログイベントの送信を担当するロギングコンポーネントです。Quarkusには、 コンソールファイルsyslog という3つの異なるログハンドラーが用意されています。

コンソールログハンドラー

コンソールログハンドラーはデフォルトで有効になっています。これはすべてのログイベントをアプリケーションのコンソールに出力します (通常はシステムの stdout )。

その設定オプションの詳細については、コンソール ロギング設定リファレンス を参照してください。

ロギングフィルタ

ログハンドラ(コンソールログハンドラのような)は、レコードが実際にログに記録されるべきかどうかを決定する目的で、それらに関連する フィルタ を持つことができます。

これらのフィルタは、 java.util.logging.Filter を実装した ( final ) クラスに @io.quarkus.logging.LoggingFilter アノテーションを配置し、 name プロパティを設定することで登録されます。

最後に、適切なハンドラの filter 設定プロパティを使用して、フィルタがアタッチされます。

例えば、コンソールログからテキストの一部を含むロギングレコードをフィルタリングしたいとしましょう。テキスト自体はアプリケーションの設定の一部であり、ハードコードされていません。このようなフィルタを書くことができます。

import io.quarkus.logging.LoggingFilter;
import java.util.logging.Filter;
import java.util.logging.LogRecord;

@LoggingFilter(name = "my-filter")
public final class TestFilter implements Filter {

    private final String part;

    public TestFilter(@ConfigProperty(name = "my-filter.part") String part) {
        this.part = part;
    }

    @Override
    public boolean isLoggable(LogRecord record) {
        return !record.getMessage().contains(part);
    }
}

そして、通常のQuarkusの方法で(たとえば、 application.properties を使用して)、次のように設定します:

my-filter.part=TEST

そして、このフィルタをコンソールハンドラにこのように登録します:

quarkus.log.console.filter=my-filter

ファイルログハンドラー

ファイルログハンドラーはデフォルトでは無効になっています。すべてのログイベントをアプリケーションのホスト上のファイルに出力します。ログファイルのローテーションをサポートしています。

その設定オプションの詳細については、ファイル ロギング設定リファレンス を参照してください。

Syslog ログハンドラー

SyslogはRFC 5424 で定義されたプロトコルを用いてUnix系システム上でログメッセージを送信するためのプロトコルです。

syslog ハンドラーは、すべてのログイベントを syslog サーバー (デフォルトでは、アプリケーションのローカルにある syslog サーバー) に送信します。デフォルトでは無効になっています。

その設定オプションの詳細については、Syslog Logging設定リファレンス を参照してください。

ルートロガーのハンドラは、通常、 quarkus.log.consolequarkus.log.file および quarkus.log.syslog によって直接設定されますが、 quarkus.log.handlers プロパティを使用して、追加の名前付きハンドラを添付することができます。

サンプル

コンソール DEBUG ログ、Quarkusのログ(INFO)を除く、カラーなし、時間短縮、カテゴリプレフィックス短縮
quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
quarkus.log.console.level=DEBUG
quarkus.console.color=false

quarkus.log.category."io.quarkus".level=INFO
コマンドラインでこれらのプロパティーを追加する場合は、 " がエスケープされていることを確認してください。例えば -Dquarkus.log.category.\"io.quarkus\".level=DEBUG のようにします。
File TRACE ログ設定
quarkus.log.file.enable=true
# Send output to a trace.log file under the /tmp directory
quarkus.log.file.path=/tmp/trace.log
quarkus.log.file.level=TRACE
quarkus.log.file.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
# Set 2 categories (io.quarkus.smallrye.jwt, io.undertow.request.security) to TRACE level
quarkus.log.min-level=TRACE
quarkus.log.category."io.quarkus.smallrye.jwt".level=TRACE
quarkus.log.category."io.undertow.request.security".level=TRACE
ルートロガーを変更しないので、コンソールログには INFO 以上の順位のログしか表示されません。
カテゴリにアタッチされた名前付きハンドラー
# Send output to a trace.log file under the /tmp directory
quarkus.log.file.path=/tmp/trace.log
quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
# Configure a named handler that logs to console
quarkus.log.handler.console."STRUCTURED_LOGGING".format=%e%n
# Configure a named handler that logs to file
quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".enable=true
quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".format=%e%n
# Configure the category and link the two named handlers to it
quarkus.log.category."io.quarkus.category".level=INFO
quarkus.log.category."io.quarkus.category".handlers=STRUCTURED_LOGGING,STRUCTURED_LOGGING_FILE
ルートロガーにアタッチされた名前付きハンドラー
# configure a named file handler that sends the output to 'quarkus.log'
quarkus.log.handler.file.CONSOLE_MIRROR.enable=true
quarkus.log.handler.file.CONSOLE_MIRROR.path=quarkus.log
# attach the handler to the root logger
quarkus.log.handlers=CONSOLE_MIRROR

集中ログ管理

ログをGraylog、Logstash、Fluentdなどの集中型ツールに送信したい場合は、 集中型ログ管理ガイド に従ってください。

@QuarkusTest のログ設定方法

@QuarkusTest のロギングを設定したい場合は、それに応じて maven-surefire-plugin を設定することを忘れないでください。特に、 java.util.logging.manager system プロパティーを使用して適切な LogManager を設定する必要があります。

設定例
<build>
  <plugins>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>${surefire-plugin.version}</version>
      <configuration>
        <systemPropertyVariables>
          <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> (1)
          <quarkus.log.level>DEBUG</quarkus.log.level>  (2)
          <maven.home>${maven.home}</maven.home>
        </systemPropertyVariables>
      </configuration>
    </plugin>
  </plugins>
</build>
1 org.jboss.logmanager.LogManager が使用されていることを確認してください。
2 すべてのロギングカテゴリのデバッグロギングを有効にします。

Gradleを使用している場合は、 build.gradle にこれを追加します。

test {
	systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}

IDEから`@QuarkusTest` を実行 も参照してください。

ロギングアダプター

Quarkusは、すべてのロギング要件をJBoss Loggingライブラリに依存しています。

Apache Commons Logging、Log4j、Slf4j などの他のロギングライブラリに依存関係があるライブラリを使用している場合は、それらを依存関係から除外し、JBoss Logging が提供するアダプターのいずれかを使用する必要があります。

ネイティブ実行可能ファイルをコンパイルする際に以下のような問題が発生する可能性があるため、ネイティブ実行可能ファイルをビルドする際には特に重要です。

Caused by java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl

これは、ロギングの実装がネイティブ実行可能ファイルに含まれていないことが原因です。JBoss Logging アダプターを使用することで、この問題は解決されます。

これらのアダプターは、Apache Commons Logging のような一般的なオープンソースのロギングコンポーネントのほとんどに対して存在します。

Apache Commons Logging:

pom.xml
<dependency>
    <groupId>org.jboss.logging</groupId>
    <artifactId>commons-logging-jboss-logging</artifactId>
</dependency>
build.gradle
implementation("org.jboss.logging:commons-logging-jboss-logging")

Log4j:

pom.xml
<dependency>
    <groupId>org.jboss.logmanager</groupId>
    <artifactId>log4j-jboss-logmanager</artifactId>
</dependency>
build.gradle
implementation("org.jboss.logmanager:log4j-jboss-logmanager")

Log4j 2:

pom.xml
<dependency>
    <groupId>org.jboss.logmanager</groupId>
    <artifactId>log4j2-jboss-logmanager</artifactId>
</dependency>
build.gradle
implementation("org.jboss.logmanager:log4j2-jboss-logmanager")

そして Slf4j:

pom.xml
<dependency>
    <groupId>org.jboss.slf4j</groupId>
    <artifactId>slf4j-jboss-logmanager</artifactId>
</dependency>
build.gradle
implementation("org.jboss.slf4j:slf4j-jboss-logmanager")
これは、Quarkusエクステンションの依存関係にあるライブラリには必要ありません。

ロギング設定リファレンス

ビルド時に固定される設定プロパティ - その他の設定プロパティは実行時にオーバーライド可能です。

Configuration property

デフォルト

The log level of the root category, which is used as the default log level for all categories.

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}

In addition, it also supports the standard JDK log levels.

Environment variable: QUARKUS_LOG_LEVEL

Level

INFO

The names of additional handlers to link to the root category. These handlers are defined in consoleHandlers, fileHandlers or syslogHandlers.

Environment variable: QUARKUS_LOG_HANDLERS

list of string

Console logging

デフォルト

If console logging should be enabled

Environment variable: QUARKUS_LOG_CONSOLE_ENABLE

boolean

true

If console logging should go to System#err instead of System#out.

Environment variable: QUARKUS_LOG_CONSOLE_STDERR

boolean

false

The log format. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension).

Environment variable: QUARKUS_LOG_CONSOLE_FORMAT

string

%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n

The console log level.

Environment variable: QUARKUS_LOG_CONSOLE_LEVEL

Level

ALL

Specify how much the colors should be darkened. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension).

Environment variable: QUARKUS_LOG_CONSOLE_DARKEN

int

0

The name of the filter to link to the console handler.

Environment variable: QUARKUS_LOG_CONSOLE_FILTER

string

Indicates whether to log asynchronously

Environment variable: QUARKUS_LOG_CONSOLE_ASYNC

boolean

false

The queue length to use before flushing writing

Environment variable: QUARKUS_LOG_CONSOLE_ASYNC_QUEUE_LENGTH

int

512

Determine whether to block the publisher (rather than drop the message) when the queue is full

Environment variable: QUARKUS_LOG_CONSOLE_ASYNC_OVERFLOW

block, discard

block

File logging

デフォルト

If file logging should be enabled

Environment variable: QUARKUS_LOG_FILE_ENABLE

boolean

false

The log format

Environment variable: QUARKUS_LOG_FILE_FORMAT

string

%d{yyyy-MM-dd HH:mm:ss,SSS} %h %N[%i] %-5p [%c{3.}] (%t) %s%e%n

The level of logs to be written into the file.

Environment variable: QUARKUS_LOG_FILE_LEVEL

Level

ALL

The name of the file in which logs will be written.

Environment variable: QUARKUS_LOG_FILE_PATH

File

quarkus.log

The name of the filter to link to the file handler.

Environment variable: QUARKUS_LOG_FILE_FILTER

string

The character encoding used

Environment variable: QUARKUS_LOG_FILE_ENCODING

Charset

Indicates whether to log asynchronously

Environment variable: QUARKUS_LOG_FILE_ASYNC

boolean

false

The queue length to use before flushing writing

Environment variable: QUARKUS_LOG_FILE_ASYNC_QUEUE_LENGTH

int

512

Determine whether to block the publisher (rather than drop the message) when the queue is full

Environment variable: QUARKUS_LOG_FILE_ASYNC_OVERFLOW

block, discard

block

The maximum file size of the log file after which a rotation is executed.

Environment variable: QUARKUS_LOG_FILE_ROTATION_MAX_FILE_SIZE

MemorySize

10M

The maximum number of backups to keep.

Environment variable: QUARKUS_LOG_FILE_ROTATION_MAX_BACKUP_INDEX

int

5

File handler rotation file suffix. When used, the file will be rotated based on its suffix. Example fileSuffix: .yyyy-MM-dd

Environment variable: QUARKUS_LOG_FILE_ROTATION_FILE_SUFFIX

string

Indicates whether to rotate log files on server initialization. You need to either set a max-file-size or configure a file-suffix for it to work.

Environment variable: QUARKUS_LOG_FILE_ROTATION_ROTATE_ON_BOOT

boolean

true

Syslog logging

デフォルト

If syslog logging should be enabled

Environment variable: QUARKUS_LOG_SYSLOG_ENABLE

boolean

false

The IP address and port of the syslog server

Environment variable: QUARKUS_LOG_SYSLOG_ENDPOINT

host:port

localhost:514

The app name used when formatting the message in RFC5424 format

Environment variable: QUARKUS_LOG_SYSLOG_APP_NAME

string

The name of the host the messages are being sent from

Environment variable: QUARKUS_LOG_SYSLOG_HOSTNAME

string

Sets the facility used when calculating the priority of the message as defined by RFC-5424 and RFC-3164

Environment variable: QUARKUS_LOG_SYSLOG_FACILITY

kernel, user-level, mail-system, system-daemons, security, syslogd, line-printer, network-news, uucp, clock-daemon, security2, ftp-daemon, ntp, log-audit, log-alert, clock-daemon2, local-use-0, local-use-1, local-use-2, local-use-3, local-use-4, local-use-5, local-use-6, local-use-7

user-level

Set the SyslogType syslog type this handler should use to format the message sent

Environment variable: QUARKUS_LOG_SYSLOG_SYSLOG_TYPE

rfc5424, rfc3164

rfc5424

Sets the protocol used to connect to the syslog server

Environment variable: QUARKUS_LOG_SYSLOG_PROTOCOL

tcp, udp, ssl-tcp

tcp

Set to true if the message being sent should be prefixed with the size of the message

Environment variable: QUARKUS_LOG_SYSLOG_USE_COUNTING_FRAMING

boolean

false

Set to true if the message should be truncated

Environment variable: QUARKUS_LOG_SYSLOG_TRUNCATE

boolean

true

Enables or disables blocking when attempting to reconnect a org.jboss.logmanager.handlers.SyslogHandler.Protocol#TCP TCP or org.jboss.logmanager.handlers.SyslogHandler.Protocol#SSL_TCP SSL TCP protocol

Environment variable: QUARKUS_LOG_SYSLOG_BLOCK_ON_RECONNECT

boolean

false

The log message format

Environment variable: QUARKUS_LOG_SYSLOG_FORMAT

string

%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n

The log level specifying, which message levels will be logged by syslog logger

Environment variable: QUARKUS_LOG_SYSLOG_LEVEL

Level

ALL

The name of the filter to link to the file handler.

Environment variable: QUARKUS_LOG_SYSLOG_FILTER

string

Indicates whether to log asynchronously

Environment variable: QUARKUS_LOG_SYSLOG_ASYNC

boolean

false

The queue length to use before flushing writing

Environment variable: QUARKUS_LOG_SYSLOG_ASYNC_QUEUE_LENGTH

int

512

Determine whether to block the publisher (rather than drop the message) when the queue is full

Environment variable: QUARKUS_LOG_SYSLOG_ASYNC_OVERFLOW

block, discard

block

Logging categories

デフォルト

The log level for this category. Note that to get log levels below INFO, the minimum level build time configuration option needs to be adjusted as well.

Environment variable: QUARKUS_LOG_CATEGORY__CATEGORIES__LEVEL

InheritableLevel

inherit

The names of the handlers to link to this category.

Environment variable: QUARKUS_LOG_CATEGORY__CATEGORIES__HANDLERS

list of string

Specify whether this logger should send its output to its parent Logger

Environment variable: QUARKUS_LOG_CATEGORY__CATEGORIES__USE_PARENT_HANDLERS

boolean

true

Console handlers

デフォルト

If console logging should be enabled

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__ENABLE

boolean

true

If console logging should go to System#err instead of System#out.

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__STDERR

boolean

false

The log format. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension).

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__FORMAT

string

%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n

The console log level.

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__LEVEL

Level

ALL

Specify how much the colors should be darkened. Note that this value will be ignored if an extension is present that takes control of console formatting (e.g. an XML or JSON-format extension).

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__DARKEN

int

0

The name of the filter to link to the console handler.

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__FILTER

string

Indicates whether to log asynchronously

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__ASYNC

boolean

false

The queue length to use before flushing writing

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__ASYNC_QUEUE_LENGTH

int

512

Determine whether to block the publisher (rather than drop the message) when the queue is full

Environment variable: QUARKUS_LOG_HANDLER_CONSOLE__CONSOLE_HANDLERS__ASYNC_OVERFLOW

block, discard

block

File handlers

デフォルト

If file logging should be enabled

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ENABLE

boolean

false

The log format

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__FORMAT

string

%d{yyyy-MM-dd HH:mm:ss,SSS} %h %N[%i] %-5p [%c{3.}] (%t) %s%e%n

The level of logs to be written into the file.

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__LEVEL

Level

ALL

The name of the file in which logs will be written.

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__PATH

File

quarkus.log

The name of the filter to link to the file handler.

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__FILTER

string

The character encoding used

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ENCODING

Charset

Indicates whether to log asynchronously

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ASYNC

boolean

false

The queue length to use before flushing writing

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ASYNC_QUEUE_LENGTH

int

512

Determine whether to block the publisher (rather than drop the message) when the queue is full

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ASYNC_OVERFLOW

block, discard

block

The maximum file size of the log file after which a rotation is executed.

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ROTATION_MAX_FILE_SIZE

MemorySize

10M

The maximum number of backups to keep.

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ROTATION_MAX_BACKUP_INDEX

int

5

File handler rotation file suffix. When used, the file will be rotated based on its suffix. Example fileSuffix: .yyyy-MM-dd

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ROTATION_FILE_SUFFIX

string

Indicates whether to rotate log files on server initialization. You need to either set a max-file-size or configure a file-suffix for it to work.

Environment variable: QUARKUS_LOG_HANDLER_FILE__FILE_HANDLERS__ROTATION_ROTATE_ON_BOOT

boolean

true

Syslog handlers

デフォルト

If syslog logging should be enabled

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__ENABLE

boolean

false

The IP address and port of the syslog server

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__ENDPOINT

host:port

localhost:514

The app name used when formatting the message in RFC5424 format

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__APP_NAME

string

The name of the host the messages are being sent from

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__HOSTNAME

string

Sets the facility used when calculating the priority of the message as defined by RFC-5424 and RFC-3164

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__FACILITY

kernel, user-level, mail-system, system-daemons, security, syslogd, line-printer, network-news, uucp, clock-daemon, security2, ftp-daemon, ntp, log-audit, log-alert, clock-daemon2, local-use-0, local-use-1, local-use-2, local-use-3, local-use-4, local-use-5, local-use-6, local-use-7

user-level

Set the SyslogType syslog type this handler should use to format the message sent

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__SYSLOG_TYPE

rfc5424, rfc3164

rfc5424

Sets the protocol used to connect to the syslog server

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__PROTOCOL

tcp, udp, ssl-tcp

tcp

Set to true if the message being sent should be prefixed with the size of the message

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__USE_COUNTING_FRAMING

boolean

false

Set to true if the message should be truncated

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__TRUNCATE

boolean

true

Enables or disables blocking when attempting to reconnect a org.jboss.logmanager.handlers.SyslogHandler.Protocol#TCP TCP or org.jboss.logmanager.handlers.SyslogHandler.Protocol#SSL_TCP SSL TCP protocol

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__BLOCK_ON_RECONNECT

boolean

false

The log message format

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__FORMAT

string

%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n

The log level specifying, which message levels will be logged by syslog logger

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__LEVEL

Level

ALL

The name of the filter to link to the file handler.

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__FILTER

string

Indicates whether to log asynchronously

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__ASYNC

boolean

false

The queue length to use before flushing writing

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__ASYNC_QUEUE_LENGTH

int

512

Determine whether to block the publisher (rather than drop the message) when the queue is full

Environment variable: QUARKUS_LOG_HANDLER_SYSLOG__SYSLOG_HANDLERS__ASYNC_OVERFLOW

block, discard

block

Log cleanup filters - internal use

デフォルト

The message starts to match

Environment variable: QUARKUS_LOG_FILTER__FILTERS__IF_STARTS_WITH

list of string

inherit

The new log level for the filtered message, defaults to DEBUG

Environment variable: QUARKUS_LOG_FILTER__FILTERS__TARGET_LEVEL

Level

DEBUG

About the MemorySize format

A size configuration option recognises string in this format (shown as a regular expression): [0-9]+[KkMmGgTtPpEeZzYy]?. If no suffix is given, assume bytes.


1. いくつかのエクステンションは、ログノイズを削減するために、特定のカテゴリに対してカスタマイズされたデフォルトログレベルを定義しているかもしれません。コンフィグレーションでのログレベル設定は、エクステンション定義のログレベルをオーバーライドします。
2. デフォルトでは設定されたカテゴリはルートロガーにアタッチされたハンドラーと同じものを受け取ります。
3. 呼び出し元の情報を検査するフォーマットシーケンスはパフォーマンスに影響する可能性があります。