Log4j-logging-levels
提供:Dev Guides
log4j-ロギングレベル
Level | Description |
---|---|
ALL | All levels including custom levels. |
DEBUG | Designates fine-grained informational events that are most useful to debug an application. |
INFO | Designates informational messages that highlight the progress of the application at coarse-grained level. |
WARN | Designates potentially harmful situations. |
ERROR | Designates error events that might still allow the application to continue running. |
FATAL | Designates very severe error events that will presumably lead the application to abort. |
OFF | The highest possible rank and is intended to turn off logging. |
TRACE | Designates finer-grained informational events than the DEBUG. |
レベルはどのように機能しますか?
レベルが q のロガー内のレベルが p のログ要求は、p> = qの場合、*有効*です。 このルールは、log4jの中心にあります。 レベルが順序付けられていることを前提としています。 標準レベルでは、ALL <DEBUG <INFO <WARN <ERROR <FATAL <OFFです。
次の例は、すべてのDEBUGおよびINFOメッセージをフィルタリングする方法を示しています。 このプログラムは、ロガーメソッドsetLevel(Level.X)を使用して、必要なログレベルを設定します。
この例では、DebugとInfoを除くすべてのメッセージを出力します。
構成ファイルを使用したレベルの設定
log4jには、デバッグレベルを変更するときにソースコードを変更しないようにする設定ファイルベースのレベル設定が用意されています。
以下は、上記の例で* log.setLevel(Level.WARN)*メソッドを使用して実行したのと同じタスクを実行する構成ファイルの例です。
次のプログラムを使用してみましょう-
上記のプログラムをコンパイルして実行すると、 /usr/home/log4j/log.out ファイルに次の結果が表示されます-