ロギング設定
Quarkus でのロギング API の使用、ロギング出力の設定、他のロギング API からの出力を統一するためのロギングアダプターの使用について解説します。
このドキュメントは、 QuarkusのObservabilityリファレンスガイド の一部です。
Quarkus uses the JBoss Log Manager logging backend for publishing application and framework logs. Quarkus supports the JBoss Logging API and multiple other logging APIs, seamlessly integrated with JBoss Log Manager.
This means you can use your favorite logging API with Quarkus, providing you add the appropriate adapter to your application:
| Logging API | Adapter |
|---|---|
Built-in |
|
Built-in |
|
アプリケーションのロギングに JBoss Logging を使用
When using the JBoss Logging API, your application requires no additional dependencies, as Quarkus provides it automatically.
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";
}
}
| While JBoss Logging routes log messages directly to the JBoss Log Manager, one of your libraries might rely on a different logging API. In such cases, you need to use a logging adapter to ensure that its log messages are routed to JBoss Log Manager as well. |
アプリケーションロガーの取得
Quarkus でアプリケーションロガーを取得するには、次のいずれかのアプローチを選択します。
ロガー・フィールドの宣言
この古典的なアプローチでは、特定のAPIを使用してロガーインスタンスを取得し、それをクラスの静的フィールドに格納し、このインスタンスに対してロギング操作を呼び出します。
supported logging APIs であれば、同じフローを適用できます。
package com.example;
import org.jboss.logging.Logger;
public class MyService {
private static final Logger log = Logger.getLogger(MyService.class); (1)
public void doSomething() {
log.info("It works!"); (2)
}
}
| 1 | ロガーフィールドを定義します。 |
| 2 | log オブジェクトに対して、必要なロギングメソッドを呼び出します。 |
|
When you create a Do not use an unbounded dynamic name for loggers, for example, |
簡易ロギング
Quarkus simplifies logging by automatically adding logger fields to classes that use io.quarkus.logging.Log.
This eliminates the need for repetitive boilerplate code and enhances the convenience of logging setup.
package com.example;
import io.quarkus.logging.Log; (1)
class MyService { (2)
public void doSomething() {
Log.info("Simple!"); (3)
}
}
| 1 | The io.quarkus.logging.Log class provides the same methods as JBoss Logging, but as static methods. |
| 2 | The class does not declare a logger field.
During the application build, Quarkus creates a private static final org.jboss.logging.Logger field in each class that uses the Log API.
Quarkus uses the fully qualified name of the calling class as the logger name.
In this example, the logger name is com.example.MyService. |
| 3 | During the application build, Quarkus rewrites calls to Log methods into JBoss Logging calls on the generated logger field. |
|
エクステンションで
io.quarkus.logging.Log を使用する:
以下の考慮事項が適用されます。
|
設定されたロガーの注入
Instead of declaring a logger field, you can use an alternative approach and inject a configured org.jboss.logging.Logger instance by using @Inject.
This approach applies only to CDI beans.
To control the logger name, choose one of the following injection patterns:
-
Use
@Inject Logger logwhen you want Quarkus to name the logger after the class it is injected into. -
Use
@LoggerName("…") Logger logwhen you want to set the logger name explicitly.
|
|
Once injected, you can use the log object to invoke logging methods.
package com.example;
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 | The logger is created with org.jboss.logging.Logger.getLogger(SimpleBean.class). |
| 2 | In this case, the name "foo" is used as a logger name.
The logger is created with org.jboss.logging.Logger.getLogger("foo"). |
|
Quarkus caches logger instances internally.
When you inject a logger into a |
ログレベルの使用
Quarkus provides multiple log levels to control the amount of information logged based on event severity.
| OFF |
ロギングをオフにするために設定で使用される特別なレベル。 |
| FATAL |
重大なサービス障害またはリクエストをまったく処理できない状態。 |
| ERROR |
処理中の重大な問題またはリクエストを完了できない状態。 |
| WARN |
重大ではないサービスエラーまたは即時の修正を必要としない可能性がある問題。 |
| INFO |
サービスライフサイクルイベントまたはその他の重要で頻度の低い情報。 |
| DEBUG |
ライフサイクルイベントまたは特定のリクエストに関連付けられていないイベントに関する追加情報。デバッグに役立ちます。 |
| TRACE |
リクエストごとの詳細なデバッグ情報。非常に高頻度で提供される可能性があります。 |
| ALL |
カスタムレベルを含むすべてのメッセージのロギングをオンにする特別なレベル。 |
java.util.logging を使用するアプリケーションやライブラリに対して、以下のレベルを設定することもできます。 :
| SEVERE |
ERROR と同じ |
| WARNING |
WARN と同じ |
| CONFIG |
サービス構成情報 |
| FINE |
DEBUG と同じ |
| FINER |
TRACE と同じ |
| FINEST |
|
| レベルの数値 | 標準レベル名 | 相当する java.util.logging (JUL) レベル名 |
|---|---|---|
1100 |
FATAL |
該当なし |
1000 |
ERROR |
SEVERE |
900 |
WARN |
WARNING |
800 |
INFO |
INFO |
700 |
該当なし |
CONFIG |
500 |
DEBUG |
FINE |
400 |
TRACE |
FINER |
300 |
該当なし |
FINEST |
ログレベル、カテゴリー、フォーマットの設定
JBoss Logging, integrated into Quarkus, provides a unified configuration for all supported logging APIs through a single configuration file that sets up all available extensions.
To adjust runtime logging, modify the application.properties file.
INFO ログに設定し、Hibernate DEBUG ログを含める方法の例です:quarkus.log.level=INFO
quarkus.log.category."org.hibernate".level=DEBUG
Assuming the Quarkus YAML extension is included, the equivalent YAML configuration is:
quarkus:
log:
level: INFO
category:
org.hibernate: # Using org.hibernate as a single key is required
level: DEBUG
When you set the log level to below DEBUG, for example TRACE, you must also adjust the minimum log level.
Set the minimum log level globally with the quarkus.log.min-level configuration property, or set it per category:
quarkus.log.category."org.hibernate".min-level=TRACE
The minimum log level is a build-time configuration option that sets the floor level for which Quarkus generates supporting code. This enables further build-time optimizations, such as dead code elimination when building a native image.
Setting INFO as the minimum log level forces checks for lower levels, such as isTraceEnabled(), always to return false.
In turn, code such as if (logger.isDebugEnabled()) callMethod(); is identified as never executed, also known as dead code.
|
コマンドラインでこれらのプロパティを追加する場合は、
|
考えられるプロパティーはすべて、logging configuration reference セクションにリストします。
ロギングカテゴリ
Logging is configured per category. Configuration for a category applies recursively to all subcategories unless a more specific subcategory configuration exists.
すべてのロギングカテゴリの親は、"ルートカテゴリ "と呼ばれます。最終的な親として、このカテゴリは他のすべてのカテゴリにグローバルに適用される設定を含むことができます。 これには、グローバルに設定されたハンドラとフォーマッタが含まれます。
quarkus.log.handlers=con,mylog
quarkus.log.handler.console.con.enable=true
quarkus.log.handler.file.mylog.enable=true
この例では、ルートカテゴリーは、 con と mylog という 2 つの名前付きハンドラーを使用するように設定されています。
quarkus.log.category."org.apache.kafka.clients".level=INFO
quarkus.log.category."org.apache.kafka.common.utils".level=INFO
This example shows how to configure the minimal log level for the categories org.apache.kafka.clients and org.apache.kafka.common.utils.
詳細は、ロギング設定リファレンス を参照してください。
特定のカテゴリーに対して特別な設定をする場合は、 quarkus.log.handler.[console|file|syslog].<your-handler-name>.* のような名前付きハンドラーを作成し、 quarkus.log.category.<my-category>.handlers を使ってそのカテゴリー用に設定します。
ユースケース例としては、ファイルに保存されるログメッセージに、他のハンドラで使用されるフォーマットとは異なるタイムスタンプ形式を使いたい場合があります。
さらに詳しい説明については、Attaching named handlers to a category 例の出力を参照してください。
| プロパティ名 | デフォルト | 説明 |
|---|---|---|
|
|
|
|
|
|
|
|
このロガーがその出力を親ロガーに送信するかどうかを指定します。 |
|
|
特定のカテゴリにアタッチしたいハンドラーの名前です。 |
|
|
ルートロガーの設定
ルート・ロガー・カテゴリーは別個に扱われ、以下のプロパティを使用して設定されます:
| プロパティ名 | デフォルト | 説明 |
|---|---|---|
|
|
各ログカテゴリのデフォルトのログレベル。 |
|
|
各ログカテゴリのデフォルトの最小ログレベル。 |
-
指定されたロガー カテゴリにレベル設定が存在しない場合、親カテゴリが調べられます。
-
カテゴリおよびその親カテゴリのいずれにも特定の設定が提供されていない場合、 ルート・ロガー設定が使用されます。
|
ルートロガーのハンドラは、通常、 |
ロギングフォーマット
Human-readable text
Quarkus は、人間が判読できるテキストログを生成するパターンベースのロギングフォーマッターをデフォルトで使用します。ただし、専用のプロパティーを使用して各ログハンドラーのフォーマットを設定することもできます。
コンソールハンドラの場合、プロパティは quarkus.log.console.format です。
ログフォーマット文字列は、以下のシンボルをサポートしています:
| Symbol | 概要 | 説明 |
|---|---|---|
|
|
単に |
|
カテゴリー |
カテゴリ名をレンダリングします。 |
|
ソースクラス |
ソースクラス名をレンダリングします。[2] |
|
日付 |
|
|
Exception |
投げられた例外があれば、その例外をレンダリングします。 |
|
ソースファイル |
ソースファイル名をレンダリングします。 [2] |
|
ホスト名 |
システムの単純なホスト名をレンダリングします。 |
|
修飾ホスト名 |
システムの完全修飾ホスト名を表示します。オペレーティングシステムの設定によっては、単純なホスト名と同じになる場合があります。 |
|
プロセスID |
現在のプロセスPIDをレンダリングします。 |
|
ソースの場所 |
ソースファイル名、行番号、クラス名、メソッド名を含むソース・ロケーション情報をレンダリングします。 [2] |
|
ソースライン |
ソース行番号をレンダリングします。 [2] |
|
フルメッセージ |
ログメッセージと例外(もしあれば)を表示します。 |
|
ソース・メソッド |
ソースメソッド名をレンダリングします。 [2] |
|
改行 |
プラットフォーム固有の改行文字列をレンダリングします。 |
|
プロセス名 |
現在のプロセスの名前をレンダリングします。 |
|
レベル |
メッセージのログレベルをレンダリングします。 |
|
相対時間 |
アプリケーションログの開始からの時間をミリ秒単位でレンダリングします。 |
|
シンプルなメッセージ |
ログメッセージのみを表示し、例外のトレースは表示しません。 |
|
スレッド名 |
スレッド名をレンダリングします。 |
|
スレッドID |
スレッドIDをレンダリングします。 |
|
タイムゾーン |
出力のタイムゾーンを |
|
マッピングされた診断コンテキスト値 |
Mapped Diagnostic Context から値をレンダリングします。 |
|
マッピングされた診断コンテキスト値 |
マッピングされた診断コンテキストからのすべての値を |
|
入れ子診断のコンテキスト値 |
ネストされた診断コンテキストからのすべての値を |
JSONロギングフォーマット
quarkus-logging-json エクステンションを使用すると、JSON ロギングフォーマットとその関連設定のサポートを追加できます。
-
以下のスニペットのように、このエクステンションをビルドファイルに追加してください:
pom.xml<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-logging-json</artifactId> </dependency>build.gradleimplementation("io.quarkus:quarkus-logging-json")By default, this extension overrides the console output format configuration, and any format string or color settings are ignored. Other console configuration items continue to apply, including items that control asynchronous logging and the log level.
If you prefer human-readable, unstructured logging in dev mode and JSON-structured logging in production mode, configure this by using profiles, as shown in the following configuration.
-
開発モードおよびテストモードで application.properties の JSON ロギングを無効にします。
%dev.quarkus.log.console.json.enabled=false %test.quarkus.log.console.json.enabled=false -
Choose the JSON console log format by setting the configuration property:
quarkus.log.console.json.log-formatThis property sets the JSON log format for the console.
The possible values are:
-
default: Generates structured logs based on the
key,valuespresent in the log record. Mapped Diagnostic Context (MDC) and Nested Diagnostic Context (NDC) data are included under themdcandndcfields. -
ecs: Uses the Elastic Common Schema (ECS) format. This format modifies some default field names and adds other fields to align with ECS.
Fields include
@timestamp,log.logger,log.level,process.pid,process.name,process.thread.name,process.thread.id,host.hostname,event.sequence,error.message,error.stack_trace,ecs.version,data_stream.type,service.name,service.version, andservice.environment. -
gcp: Uses the Google Cloud format. This format follows the default format.
When you use OpenTelemetry, Quarkus flattens tracing data present in the
mdcfield and copies it tospanId,traceSampled, andtrace, with thetracevalue including a prefix.Google Cloud requires the
tracefield to follow the"projects/<my-trace-project>/traces/12345"format.<my-trace-project>uses the value of thequarkus.application.nameconfiguration property.
-
Configuration (設定)
サポートされているプロパティを使用してJSONロギングエクステンションを設定し、その動作をカスタマイズしてください。
ビルド時に固定された設定プロパティー。その他の設定プロパティーはすべて実行時にオーバーライド可能です。
Configuration property |
型 |
デフォルト |
|---|---|---|
型 |
デフォルト |
|
Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting. Environment variable: Show more |
boolean |
|
Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read the pretty printed output. Environment variable: Show more |
boolean |
|
The date format to use. The special string "default" indicates that the default format should be used. Environment variable: Show more |
string |
|
The special end-of-record delimiter to be used. By default, newline is used. Environment variable: Show more |
string |
|
The zone ID to use. The special string "default" indicates that the default zone should be used. Environment variable: Show more |
string |
|
The exception output type to specify. Environment variable: Show more |
|
|
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: Show more |
boolean |
|
Override keys with custom values. Omitting this value indicates that no key overrides will be applied. Environment variable: Show more |
string |
|
Keys to be excluded from the JSON output. Environment variable: Show more |
list of string |
|
Additional field value. Environment variable: Show more |
string |
required |
Additional field type specification. Supported types: Environment variable: Show more |
|
|
Specify the format of the produced JSON Environment variable: Show more |
|
|
型 |
デフォルト |
|
Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting. Environment variable: Show more |
boolean |
|
Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read the pretty printed output. Environment variable: Show more |
boolean |
|
The date format to use. The special string "default" indicates that the default format should be used. Environment variable: Show more |
string |
|
The special end-of-record delimiter to be used. By default, newline is used. Environment variable: Show more |
string |
|
The zone ID to use. The special string "default" indicates that the default zone should be used. Environment variable: Show more |
string |
|
The exception output type to specify. Environment variable: Show more |
|
|
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: Show more |
boolean |
|
Override keys with custom values. Omitting this value indicates that no key overrides will be applied. Environment variable: Show more |
string |
|
Keys to be excluded from the JSON output. Environment variable: Show more |
list of string |
|
Additional field value. Environment variable: Show more |
string |
required |
Additional field type specification. Supported types: Environment variable: Show more |
|
|
Specify the format of the produced JSON Environment variable: Show more |
|
|
型 |
デフォルト |
|
Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting. Environment variable: Show more |
boolean |
|
Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read the pretty printed output. Environment variable: Show more |
boolean |
|
The date format to use. The special string "default" indicates that the default format should be used. Environment variable: Show more |
string |
|
The special end-of-record delimiter to be used. By default, newline is used. Environment variable: Show more |
string |
|
The zone ID to use. The special string "default" indicates that the default zone should be used. Environment variable: Show more |
string |
|
The exception output type to specify. Environment variable: Show more |
|
|
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: Show more |
boolean |
|
Override keys with custom values. Omitting this value indicates that no key overrides will be applied. Environment variable: Show more |
string |
|
Keys to be excluded from the JSON output. Environment variable: Show more |
list of string |
|
Additional field value. Environment variable: Show more |
string |
required |
Additional field type specification. Supported types: Environment variable: Show more |
|
|
Specify the format of the produced JSON Environment variable: Show more |
|
|
型 |
デフォルト |
|
Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting. Environment variable: Show more |
boolean |
|
Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read the pretty printed output. Environment variable: Show more |
boolean |
|
The date format to use. The special string "default" indicates that the default format should be used. Environment variable: Show more |
string |
|
The special end-of-record delimiter to be used. By default, newline is used. Environment variable: Show more |
string |
|
The zone ID to use. The special string "default" indicates that the default zone should be used. Environment variable: Show more |
string |
|
The exception output type to specify. Environment variable: Show more |
|
|
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: Show more |
boolean |
|
Override keys with custom values. Omitting this value indicates that no key overrides will be applied. Environment variable: Show more |
string |
|
Keys to be excluded from the JSON output. Environment variable: Show more |
list of string |
|
Additional field value. Environment variable: Show more |
string |
required |
Additional field type specification. Supported types: Environment variable: Show more |
|
|
Specify the format of the produced JSON Environment variable: Show more |
|
|
| プリティプリント (pretty printing) を有効にすると、特定のプロセッサーやJSONパーサーで解釈できなくなる可能性があります。 |
| 詳細の表示は、呼び出し元から値を取得するため、コストがかかる場合があります。詳細には、ソースクラス名、ソースファイル名、ソースメソッド名、ソース行番号などが含まれます。 |
ログハンドラー
A log handler is a logging component that emits log events to a recipient. Quarkus includes several different log handlers: console, file, and syslog.
特集の例では、 com.example をロギング・カテゴリーとして使用しています。
コンソールログハンドラー
コンソールログハンドラーはデフォルトで有効になっており、すべてのログイベントをアプリケーションのコンソール(通常はシステムの stdout )に送ります。
-
グローバル設定の例:
quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) %s%e%n -
カテゴリーごとの設定の例:
quarkus.log.handler.console.my-console-handler.format=%d{yyyy-MM-dd HH:mm:ss} [com.example] %s%e%n quarkus.log.category."com.example".handlers=my-console-handler quarkus.log.category."com.example".use-parent-handlers=false
設定の詳細は、コンソールロギング設定 リファレンスを参照してください。
ファイルログハンドラー
To log events to a file on the application’s host, use the Quarkus file log handler. The file log handler is disabled by default, so you must enable it first.
Quarkus ファイルログハンドラーは、ログファイルのローテーションをサポートします。
Log file rotation ensures efficient log management by preserving a specified number of backup files while keeping the primary log file up to date and manageable in size.
-
グローバル設定の例:
quarkus.log.file.enabled=true quarkus.log.file.path=application.log quarkus.log.file.format=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) %s%e%n -
カテゴリーごとの設定の例:
quarkus.log.handler.file.my-file-handler.enabled=true quarkus.log.handler.file.my-file-handler.path=application.log quarkus.log.handler.file.my-file-handler.format=%d{yyyy-MM-dd HH:mm:ss} [com.example] %s%e%n quarkus.log.category."com.example".handlers=my-file-handler quarkus.log.category."com.example".use-parent-handlers=false
設定の詳細は、ファイルログ設定 リファレンスを参照してください。
Syslog ログハンドラー
Quarkus の syslog ハンドラーは、 Syslog プロトコルに従います。このプロトコルは、UNIX ライクなシステムでログメッセージを送信するために使用されます。 このログハンドラーは、RFC 5424 で定義されたプロトコルを使用します。
デフォルトでは、syslogハンドラは無効になっています。 有効にすると、すべてのログイベントを syslog サーバー(通常はアプリケーションのローカル syslog サーバー)に送信します。
-
グローバル設定の例:
quarkus.log.syslog.enabled=true quarkus.log.syslog.app-name=my-application quarkus.log.syslog.format=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) %s%e%n -
カテゴリーごとの設定の例:
quarkus.log.handler.syslog.my-syslog-handler.enabled=true quarkus.log.handler.syslog.my-syslog-handler.app-name=my-application quarkus.log.handler.syslog.my-syslog-handler.format=%d{yyyy-MM-dd HH:mm:ss} [com.example] %s%e%n quarkus.log.category."com.example".handlers=my-syslog-handler quarkus.log.category."com.example".use-parent-handlers=false
設定の詳細は、システムロギング設定 リファレンスを参照してください。
Socket ログハンドラー
This handler sends logs to a socket. The socket log handler is disabled by default; enable it to use it. When enabled, it sends all log events to a socket, such as a Logstash server.
-
グローバル設定の例:
quarkus.log.socket.enabled=true quarkus.log.socket.endpoint=localhost:4560
通常、このハンドラは quarkus-logging-json エクステンションと一緒に使用し、ECS 形式のログを Elasticsearch インスタンスに送信します。
設定例については、 集中ログ管理 ガイドを参照してください。
ログハンドラーに対するロギングフィルタの追加
You can attach a filter to a log handler such as the console handler. The filter determines whether the handler logs a given log record.
ロギングフィルターの登録方法
-
java.util.logging.Filterを実装するfinalクラスを@io.quarkus.logging.LoggingFilterでアノテートし、nameプロパティを設定します:フィルターの書き方の例:package com.example; 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); } }この例では、コンソールログから特定のテキストを含むログレコードを除外します。 フィルタリングする特定のテキストはハードコードされておらず、
my-filter.part設定プロパティから読み込まれます。application.propertiesにおけるフィルターの設定例:my-filter.part=TEST -
application.propertiesにあるfilter設定プロパティを使用して、対応するハンドラにフィルタをアタッチします:quarkus.log.console.filter=my-filter
ロギング設定の例
The following examples show how to configure logging in Quarkus:
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
|
コマンドラインでこれらのプロパティを追加する場合、忘れずに |
quarkus.log.file.enabled=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".enabled=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.enabled=true
quarkus.log.handler.file.CONSOLE_MIRROR.path=quarkus.log
# attach the handler to the root logger
quarkus.log.handlers=CONSOLE_MIRROR
ログの一元管理
Use a centralized location to efficiently collect, store, and analyze log data from various components and application instances.
Graylog、Logstash、Fluentdなどの集中型ツールにログを送信するには、Quarkusの 集中型ログ管理 ガイドを参照してください。
OpenTelemetry ログ
You can enable sending log entries from all appenders to OpenTelemetry Logging.
詳細は、Quarkus OpenTelemetry Logging ガイドを参照してください。
@QuarkusTest のロギング設定
To enable logging for @QuarkusTest, it is necessary to set the java.util.logging.manager system property to org.jboss.logmanager.LogManager early in the startup process, or logging will not work as expected.
Configure it in your build tool as follows:
-
For Maven:
Set the property in the Maven Surefire plugin configuration.
Settingjava.util.logging.managerin the Maven Surefire plugin configuration:<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の場合:
Set the property in the
build.gradlefile.test { systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" }
For more information, see the Running @QuarkusTest from an IDE section of the Testing your Application guide.
他のロギングAPIの使用
Quarkus relies on the JBoss Logging library for logging. If your dependencies use other logging APIs, such as Apache Commons Logging, Log4j, or SLF4J, exclude those libraries and use a JBoss Logging adapter. This step is especially important for native executables, because the native build can fail with errors such as the following:
Caused by java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl
The native executable does not include the logging implementation for those APIs. Use JBoss Logging adapters to resolve this issue.
The next section describes adapters for common open-source logging APIs.
アプリケーションにロギングアダプタを追加
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. You can then verify whether the logs generated by the added library adhere to the same format as the other Quarkus logs.
| Quarkusエクステンションの依存ライブラリで、エクステンションが自動的に処理する場合は、この手順は不要です。 |
SLF4J
The SLF4J adapter is provided by the following dependency:
<dependency>
<groupId>org.jboss.slf4j</groupId>
<artifactId>slf4j-jboss-logmanager</artifactId>
</dependency>
implementation("org.jboss.slf4j:slf4j-jboss-logmanager")
Apache Commons Logging
The Commons Logging adapter is provided by the following dependency:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
</dependency>
implementation("org.jboss.logging:commons-logging-jboss-logging")
Log4j 2
The Log4j 2 adapter is provided by the following dependency:
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>log4j2-jboss-logmanager</artifactId>
</dependency>
implementation("org.jboss.logmanager:log4j2-jboss-logmanager")
|
|
MDCを使用してコンテキストログ情報を追加
Quarkus は、リアクティブコアとの互換性を高めるために、ロギングの Mapped Diagnostic Context (MDC) をオーバーライドします。
MDCデータの追加と読込
MDCにデータを追加し、ログ出力に抽出するには以下のように行います:
-
MDCクラスを使ってデータをセットします。-
import org.jboss.logmanager.MDC;を追加します。 -
以下の例に示すように、
MDC.put(…)を設定します。JBoss Logging とio.quarkus.logging.Logの例package me.sample; import io.quarkus.logging.Log; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import org.jboss.logmanager.MDC; import java.util.UUID; @Path("/hello/jboss") public class GreetingResourceJbossLogging { @GET @Path("/test") public String greeting() { MDC.put("request.id", UUID.randomUUID().toString()); MDC.put("request.path", "/hello/test"); Log.info("request received"); return "hello world!"; } }
-
-
ログ形式を
%X {mdc-key}を使用するように設定します。quarkus.log.console.format=%d{HH:mm:ss} %-5p request.id=%X{request.id} request.path=%X{request.path} [%c{2.}] (%t) %s%n結果のメッセージには MDC データが含まれます。
08:48:13 INFO request.id=c37a3a36-b7f6-4492-83a1-de41dbc26fe2 request.path=/hello/test [me.sa.GreetingResourceJbossLogging] (executor-thread-1) request received
MDCとサポートされるロギングAPI
ロギング API に応じて、次のいずれかの MDC クラスを使用します。
-
Log4j 1 -
org.apache.log4j.MDC.put(key, value) -
Log4j 2 -
org.apache.logging.log4j.ThreadContext.put(key, value) -
SLF4J -
org.slf4j.MDC.put(key, value)
MDCの伝播
Quarkusでは、MDCプロバイダにはリアクティブコンテキストを処理するための特別な実装があり、リアクティブ処理や非同期処理中にMDCデータが確実に伝搬されます。
その結果、さまざまなシナリオでMDCデータにアクセスすることができます:
-
非同期呼び出しの後、例えばRESTクライアントがUniを返す場合:
-
org.eclipse.microprofile.context.ManagedExecutorに送信されたコードで: -
vertx.executeBlocking()で実行されるコードで:
| If applicable, Quarkus stores MDC data in a Vert.x duplicated context, which isolates processing for a single task or request. |
ロギング設定リファレンス
ビルド時に固定された設定プロパティー。その他の設定プロパティーはすべて実行時にオーバーライド可能です。
Configuration property |
タイプ |
デフォルト |
|---|---|---|
If enabled and a metrics extension is present, logging metrics are published. Environment variable: Show more |
ブーリアン |
|
The default minimum log level. Environment variable: Show more |
|
|
This will decorate the stacktrace in dev mode to show the line in the code that cause the exception Environment variable: Show more |
ブーリアン |
|
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:
In addition, it also supports the standard JDK log levels. Environment variable: Show more |
|
|
The names of additional handlers to link to the root category. These handlers are defined in consoleHandlers, fileHandlers, or syslogHandlers. Environment variable: Show more |
list of string |
|
タイプ |
デフォルト |
|
The minimum log level for this category. By default, all categories are configured with To get runtime logging below As an example, to get Environment variable: Show more |
InheritableLevel |
|
The log level for this category. Note that to get log levels below Environment variable: Show more |
InheritableLevel |
|
The names of the handlers to link to this category. Environment variable: Show more |
list of string |
|
Specify whether this logger should send its output to its parent Logger Environment variable: Show more |
ブーリアン |
|
タイプ |
デフォルト |
|
If console logging should be enabled Environment variable: Show more |
ブーリアン |
|
If console logging should go to Environment variable: Show more |
ブーリアン |
|
The log format. Note that this value is ignored if an extension is present that takes control of console formatting (e.g., an XML or JSON-format extension). Environment variable: Show more |
string |
|
The console log level. Environment variable: Show more |
|
|
Specify how much the colors should be darkened. Note that this value is ignored if an extension is present that takes control of console formatting (e.g., an XML or JSON-format extension). Environment variable: Show more |
int |
|
The name of the filter to link to the console handler. Environment variable: Show more |
string |
|
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
タイプ |
デフォルト |
|
If file logging should be enabled Environment variable: Show more |
ブーリアン |
|
string |
|
|
The level of logs to be written into the file. Environment variable: Show more |
|
|
The name of the file in which logs will be written. Environment variable: Show more |
|
|
The name of the filter to link to the file handler. Environment variable: Show more |
string |
|
The character encoding used Environment variable: Show more |
||
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
Whether log rotation is enabled. Environment variable: Show more |
ブーリアン |
|
The maximum log file size, after which a rotation is executed, up to Environment variable: Show more |
|
|
The maximum number of backups to keep. Environment variable: Show more |
int |
|
The file handler rotation file suffix. When used, the file will be rotated based on its suffix. The suffix must be in a date-time format that is understood by Example fileSuffix: .yyyy-MM-dd Note: If the suffix ends with .zip or .gz, the rotation file will also be compressed. Environment variable: Show more |
string |
|
Indicates whether to rotate log files on server initialization. You need to either set a Environment variable: Show more |
ブーリアン |
|
タイプ |
デフォルト |
|
If syslog logging should be enabled Environment variable: Show more |
ブーリアン |
|
The IP address and port of the Syslog server Environment variable: Show more |
host:port |
|
The app name used when formatting the message in RFC5424 format Environment variable: Show more |
string |
|
The name of the host the messages are being sent from Environment variable: Show more |
string |
|
Sets the facility used when calculating the priority of the message as defined by RFC-5424 and RFC-3164 Environment variable: Show more |
|
|
Set the Environment variable: Show more |
|
|
Sets the protocol used to connect to the Syslog server Environment variable: Show more |
|
|
If enabled, the message being sent is prefixed with the size of the message Environment variable: Show more |
|
|
Set to Environment variable: Show more |
ブーリアン |
|
Enables or disables blocking when attempting to reconnect a Environment variable: Show more |
ブーリアン |
|
The log message format Environment variable: Show more |
string |
|
The log level specifying what message levels will be logged by the Syslog logger Environment variable: Show more |
|
|
The name of the filter to link to the file handler. Environment variable: Show more |
string |
|
The maximum length, in bytes, of the message allowed to be sent, up to If not set, the default value is Environment variable: Show more |
||
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
タイプ |
デフォルト |
|
If socket logging should be enabled Environment variable: Show more |
ブーリアン |
|
The IP address and port of the server receiving the logs Environment variable: Show more |
host:port |
|
Sets the protocol used to connect to the syslog server Environment variable: Show more |
|
|
Enables or disables blocking when attempting to reconnect a Environment variable: Show more |
ブーリアン |
|
The log message format Environment variable: Show more |
string |
|
The log level specifying, which message levels will be logged by socket logger Environment variable: Show more |
|
|
The name of the filter to link to the file handler. Environment variable: Show more |
string |
|
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
タイプ |
デフォルト |
|
If console logging should be enabled Environment variable: Show more |
ブーリアン |
|
If console logging should go to Environment variable: Show more |
ブーリアン |
|
The log format. Note that this value is ignored if an extension is present that takes control of console formatting (e.g., an XML or JSON-format extension). Environment variable: Show more |
string |
|
The console log level. Environment variable: Show more |
|
|
Specify how much the colors should be darkened. Note that this value is ignored if an extension is present that takes control of console formatting (e.g., an XML or JSON-format extension). Environment variable: Show more |
int |
|
The name of the filter to link to the console handler. Environment variable: Show more |
string |
|
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
タイプ |
デフォルト |
|
If file logging should be enabled Environment variable: Show more |
ブーリアン |
|
The log format Environment variable: Show more |
string |
|
The level of logs to be written into the file. Environment variable: Show more |
|
|
The name of the file in which logs will be written. Environment variable: Show more |
|
|
The name of the filter to link to the file handler. Environment variable: Show more |
string |
|
The character encoding used Environment variable: Show more |
||
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
Whether log rotation is enabled. Environment variable: Show more |
ブーリアン |
|
The maximum log file size, after which a rotation is executed, up to Environment variable: Show more |
|
|
The maximum number of backups to keep. Environment variable: Show more |
int |
|
The file handler rotation file suffix. When used, the file will be rotated based on its suffix. The suffix must be in a date-time format that is understood by Example fileSuffix: .yyyy-MM-dd Note: If the suffix ends with .zip or .gz, the rotation file will also be compressed. Environment variable: Show more |
string |
|
Indicates whether to rotate log files on server initialization. You need to either set a Environment variable: Show more |
ブーリアン |
|
タイプ |
デフォルト |
|
If syslog logging should be enabled Environment variable: Show more |
ブーリアン |
|
The IP address and port of the Syslog server Environment variable: Show more |
host:port |
|
The app name used when formatting the message in RFC5424 format Environment variable: Show more |
string |
|
The name of the host the messages are being sent from Environment variable: Show more |
string |
|
Sets the facility used when calculating the priority of the message as defined by RFC-5424 and RFC-3164 Environment variable: Show more |
|
|
Set the Environment variable: Show more |
|
|
Sets the protocol used to connect to the Syslog server Environment variable: Show more |
|
|
If enabled, the message being sent is prefixed with the size of the message Environment variable: Show more |
|
|
Set to Environment variable: Show more |
ブーリアン |
|
Enables or disables blocking when attempting to reconnect a Environment variable: Show more |
ブーリアン |
|
The log message format Environment variable: Show more |
string |
|
The log level specifying what message levels will be logged by the Syslog logger Environment variable: Show more |
|
|
The name of the filter to link to the file handler. Environment variable: Show more |
string |
|
The maximum length, in bytes, of the message allowed to be sent, up to If not set, the default value is Environment variable: Show more |
||
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
タイプ |
デフォルト |
|
If socket logging should be enabled Environment variable: Show more |
ブーリアン |
|
The IP address and port of the server receiving the logs Environment variable: Show more |
host:port |
|
Sets the protocol used to connect to the syslog server Environment variable: Show more |
|
|
Enables or disables blocking when attempting to reconnect a Environment variable: Show more |
ブーリアン |
|
The log message format Environment variable: Show more |
string |
|
The log level specifying, which message levels will be logged by socket logger Environment variable: Show more |
|
|
The name of the filter to link to the file handler. Environment variable: Show more |
string |
|
Whether to log asynchronously Environment variable: Show more |
ブーリアン |
|
The queue length to use before flushing writing Environment variable: Show more |
int |
|
Determine whether to block the publisher (rather than drop the message) when the queue is full Environment variable: Show more |
|
|
タイプ |
デフォルト |
|
The message prefix to match Environment variable: Show more |
list of string |
|
The new log level for the filtered message. Defaults to DEBUG. Environment variable: Show more |
|
|
MemorySizeフォーマットについて
A size configuration option recognizes strings in this format (shown as a regular expression): If no suffix is given, assume bytes. |