org.apache.log4j
クラス PropertyConfigurator

java.lang.Object
  |
  +--org.apache.log4j.BasicConfigurator
        |
        +--org.apache.log4j.PropertyConfigurator
すべての実装インタフェース:
Configurator

public class PropertyConfigurator
extends BasicConfigurator
implements Configurator

Extends BasicConfigurator to provide configuration from an external file. See doConfigure(String, Hierarchy) for the expected format.

外部ファイルから設定内容を供給するために BasicConfigurator を拡張します。 求められるフォーマットに関しては、doConfigure(String, Hierarchy) を参照してください。

It is sometimes useful to see how log4j is reading configuration files. You can enable log4j internal logging by defining the log4j.debug variable.

log4jがどのように設定ファイルを読んでいるかを調べるのは、時として役立ちます。 あなたは、log4j.debug変数を定義することでlog4jの内部ロギングを可能にします。

As of log4j version 0.8.5, at the initialization of the Category class, the file log4j.properties will be searched from the search path used to load classes. If the file can be found, then it will be fed to the configure(java.net.URL) method.

log4jがバージョン 0.8.5 になって 、Categoryクラスの初期化時にファイル log4j.properties がクラスロード時に使う検索パスから検索される ようになります。 もし、ファイルが見つかった場合、それは、 configure(java.net.URL)メソッドに遷移します。

The PropertyConfigurator does not handle the advanced configuration features supported by the DOMConfigurator such as support for Filters, custom ErrorHandlers, nested appenders such as the AsyncAppender, etc.

PropertyConfiguratorは、Filters をサポートするような DOMConfigurator や、カスタム ErrorHandlersAsyncAppenderのようなネスとしたアペンダなどの によりサポートされる特徴をもつ進んだ設定を処理しません。

All option values admit variable substitution. For example, if java.home system property is set to /home/xyz and the File option is set to the string ${java.home}/test.log, then File option will be interpreted as the string /home/xyz/test.log.

全てのオプション変数は、変数置換を許可します。 例えば、もし、java.homeシステムプロパティが /home/xyzに設定され、Fileオプションが、文字列 ${java.home}/test.logに設定された場合、 Fileオプションは、/home/xyz/test.logとして解釈されます。

The value of the substituted variable can be defined as a system property or in the configuration file file itself.

置き換えられた変数の値は、システムプロパティまたは、設定ファイル内自体に 定義されます。

The syntax of variable substitution is similar to that of UNIX shells. The string between an opening "${" and closing "}" is interpreted as a key. Its value is searched in the system properties, and if not founf then in the configuration file being parsed. The corresponding value replaces the ${variableName} sequence.

変数置換の構文は、UNIXシェルのものと同じです。 最初の"${"と閉じの"}"の間の文字列がキーとして 解釈されます。 その値は、システムプロパティ内で検索され、もし見つからなければ、解析中の 設定ファイル内で検索されます。 対になるアタイは、${variableName}シーケンスを置き換えます。

導入されたバージョン:
0.8.1
作成者:
Ceki Gülcü, Anders Kristensen

フィールドの概要
static String CATEGORY_FACTORY_KEY
          Key for specifying the CategoryFactory.
protected  CategoryFactory categoryFactory
           
protected  Hashtable registry
          Used internally to keep track of configured appenders.
 
クラス org.apache.log4j.BasicConfigurator から継承したフィールド
DISABLE_KEY, DISABLE_OVERRIDE_KEY, INHERITED
 
コンストラクタの概要
PropertyConfigurator()
           
 
メソッドの概要
static void configure(Properties properties)
          Read configuration options from properties.
static void configure(String configFilename)
           
static void configure(URL configURL)
          Read configuration options from url configURL.
static void configureAndWatch(String configFilename)
          Like configureAndWatch(String, long) except that the default delay as defined by FileWatchdog.DEFAULT_DELAY is used.
static void configureAndWatch(String configFilename, long delay)
          Read the configuration file configFilename if it exists.
protected  void configureCategoryFactory(Properties props)
          Check the provided Properties object for a CategoryFactory entry specified by CATEGORY_FACTORY_KEY.
 void doConfigure(Properties properties, Hierarchy hierarchy)
          Read configuration options from properties.
 void doConfigure(String configFileName, Hierarchy hierarchy)
          Read configuration from a file.
 void doConfigure(URL configURL, Hierarchy hierarchy)
          Read configuration options from url configURL.
protected  void parseCatsAndRenderers(Properties props, Hierarchy hierarchy)
          Parse non-root elements, such non-root categories and renderers.
 
クラス org.apache.log4j.BasicConfigurator から継承したメソッド
addRenderer, configure, configure, disable, disable, disableAll, disableDebug, disableInfo, enableAll, resetConfiguration, resetConfiguration
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

registry

protected Hashtable registry
Used internally to keep track of configured appenders.

設定されたアペンダの流れを保つために内部で使われます。


categoryFactory

protected CategoryFactory categoryFactory

CATEGORY_FACTORY_KEY

public static final String CATEGORY_FACTORY_KEY
Key for specifying the CategoryFactory. Currently set to "log4j.categoryFactory".

CategoryFactory を設定するためのキーです。 現状、"log4j.categoryFactory"に設定されています。

コンストラクタの詳細

PropertyConfigurator

public PropertyConfigurator()
メソッドの詳細

doConfigure

public void doConfigure(String configFileName,
                        Hierarchy hierarchy)
Read configuration from a file. The existing configuration is not cleared nor reset. If you require a different behavior, then call resetConfiguration method before calling doConfigure.

ファイルから設定内容を読み込みます。 存在する設定内容は、クリアもリセットもされません。 もし、異なる振る舞いを要求する場合は、doConfigureを呼び出す 前に、resetConfiguration を呼び出してください。

The configuration file consists of statements in the format key=value. The syntax of different configuration elements are discussed below.

設定ファイルは、フォーマット key=valueのステートメントから成ります。

Appender configuration

アペンダの設定

Appender configuration syntax is:

アペンダの設定構文は、以下のようになっています:

# For appender named appenderName, set its class.

# appenderNameとなっているアペンダには、クラスを設定します。

# Note: The appender name can contain dots.

# 注意: アペンダ名には、ドットを含めることができます。

log4j.appender.appenderName=fully.qualified.name.of.appender.class # Set appender specific options.

# アペンダの具体的なオプションを設定します。

log4j.appender.appenderName.option1=value1 ... log4j.appender.appenderName.optionN=valueN

For each named appender you can configure its Layout. The syntax for configuring an appender's layout is:

各名づけられたアペンダに関しては、Layoutを設定できます。 アペンダのレイアウトの設定構文は、以下のようになっています:

log4j.appender.appenderName.layout=fully.qualified.name.of.layout.class
log4j.appender.appenderName.layout.option1=value1
....
log4j.appender.appenderName.layout.optionN=valueN

Configuring categories

カテゴリの設定

The syntax for configuring the root category is:

ルートカテゴリの設定構文は、以下のようになっています:

log4j.rootCategory=[priority], appenderName, appenderName, ...

This syntax means that an optional priority value can be supplied followed by appender names separated by commas.

この構文は、オプションの priority valueがカンマで区切りで名前指定された アペンダによって次のものを提供できることを意味しています。

The priority value can consist of the string values FATAL, ERROR, WARN, INFO, DEBUG or a custom priority value. A custom priority value can be specified in the form priority#classname.

優先度の値は、文字列値 FATAL、ERROR、WARN、INFO、DEBUGまたは custom priority値から成ります。 カスタム優先度値は、フォーム priority#classnameで指定できます。

If a priority value is specified, then the root priority is set to the corresponding priority. If no priority value is specified, then the root priority remains untouched.

もし、優先度の値が指定されている場合は、ルートの優先度は、 一致する優先度に設定されます。 もし、優先度の値が設定されていない場合は、ルートの優先度は、 設定されないままです。

The root category can be assigned multiple appenders.

ルートのカテゴリには、複数のアペンダを割り当てることができます。

Each appenderName (separated by commas) will be added to the root category. The named appender is defined using the appender syntax defined above.

appenderName (カンマ区切り)はるーとカテゴリに追加されます。 名前指定されたアペンダは、上記で定義されたアペンダの構文を使って定義されます。

For non-root categories the syntax is almost the same:

ルートのカテゴリでないものに関しては、 構文は、ほとんど同じで以下のようないなります:

log4j.category.category_name=[priority|INHERITED], appenderName, appenderName, ...

The meaning of the optional priority value is discussed above in relation to the root category. In addition however, the value INHERITED can be specified meaning that the named category should inherit its priority from the category hierarchy.

オプション優先度の値の意味は、ルートのカテゴリと関連して上記で説明されています。 しかし、追加として、名前指定されたカテゴリがカテゴリ階層から優先度を継承する という意味で、値INHERITEDが指定できます。

If no priority value is supplied, then the priority of the named category remains untouched.

もし、優先度の値が与えられない場合は、名前指定されたカテゴリの優先度は、 設定されないままです。

By default categories inherit their priority from the hierarchy. However, if you set the priority of a category and later decide that that category should inherit its priority, then you should specify INHERITED as the value for the priority value.

デフォルトでは、カテゴリは、階層からそれらの優先度を継承します。 しかし、もし、あなたが、カテゴリの優先度を設定せず、カテゴリが優先度を継承する べきだと後になって決めた場合、その時は、優先度の値に対して、値として INHERITEDを指定することになります。

Similar to the root category syntax, each appenderName (separated by commas) will be attached to the named category.

ルートのカテゴリの構文と同様に、各 appenderName(カンマ区切り)は、 名前指定されたカテゴリにアタッチされます。

See the appender additivity rule in the user manual for the meaning of the additivity flag.

additivityフラグの意味に関しては、ユーザマニュアルの アペンダー additivityルール を参照してください。

The user can override any of the Hierarchy.disable(java.lang.String) family of methods by setting the a key "log4j.disableOverride" to true or any value other than false. As in

log4j.disableOverride=true 

ユーザは、キー "log4j.disableOverride"をtrueまたは、 false以外の値を設定することでメソッドファミリー Hierarchy.disable(java.lang.String) をオーバーライドできます。

ObjectRenderers

オブジェクトレンダラー

You can customize the way message objects of a given type are converted to String before being logged. This is done by specifying an ObjectRenderer for the object type would like to customize.

あなたは、与えられたタイプのメッセージオブジェクトがログ出力される前に 文字列に変換する方法をカスタマイズすることができます。

The syntax is:

構文は、以下のようなります:

log4j.renderer.fully.qualified.name.of.rendered.class=fully.qualified.name.of.rendering.class
As in,

置き換えると以下のようになります,

log4j.renderer.my.Fruit=my.FruitRenderer

Class Factories

クラスファクトリ

In case you are using your own subtypes of the Category class and wish to use configuration files, then you must set the categoryFactory for the subtype that you are using.

あなたが、Categoryクラスの自分自身のサブタイプを使い、 設定ファイルを使いたい場合は、あなたが使っているサブタイプに関する categoryFactoryを設定する必要があります。

The syntax is:

その構文は、以下のようになります:

log4j.categoryFactory=fully.qualified.name.of.categoryFactory.class
See MyCategory for an example.

例に関しては、MyCategory を参照してください。

Example

An example configuration is given below. Other configuration file examples are given in Sort class documentation.

設定例は以下に示す通りです。 他の設定ファイルの例は、Sortクラスの ドキュメントに示しています。


# Set options for appender named "A1". 

# アペンダ名 "A1" としてオプションを設定します。

# Appender "A1" will be a SyslogAppender

# アペンダ "A1" は、SyslogAppenderです。

log4j.appender.A1=org.apache.log4j.net.SyslogAppender # The syslog daemon resides on www.abc.net

# syslogデーモンは、www.abc.net上に存在します。

log4j.appender.A1.SyslogHost=www.abc.net # A1's layout is a PatternLayout, using the conversion pattern # %r %-5p %c{2} %M.%L %x - %m\n. Thus, the log output will # include # the relative time since the start of the application in # milliseconds, followed by the priority of the log request, # followed by the two rightmost components of the category name, # followed by the callers method name, followed by the line number, # the nested disgnostic context and finally the message itself. # Refer to the documentation of PatternLayout for further information # on the syntax of the ConversionPattern key.

# A1のレイアウトは、PatternLayoutで、変換パタンとして # %r %-5p %c{2} %M %M.%L %x - %m%nを使います。 # それに従い、ログの出力は、ミリ秒で表されるアプリケーション開始時の相対時間、 # 次に、ログ要求の優先度、次に、カテゴリ名の第2コンポーネント、次に、 # 呼び出されるメソッド名、次に、行番号、ネスト化診断コンテキスト、最後に # メッセージ自体が含まれています。 # ConversionPatternのキーの構文のさらなる情報は、 # PatternLayoutのドキュメントを参照してください。

log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %c{2} %M.%L %x - %m\n # Set options for appender named "A2"

# アペンダ名 "A2" に関するオプションを設定します。

# A2 should be a RollingFileAppender, with maximum file size of 10 MB # using at most one backup file. A2's layout is TTCC, using the # ISO8061 date format with context printing enabled.

# A2 は、一つのバックアップファイルを使い、ファイルの最大値が10MBに設定した # RollingFileAppender です。 # A2のレイアウトは、TTCCで、出力可能なコンテキストと共に、ISO8061の # デーフォーマットを使います。

log4j.appender.A2=org.apache.log4j.RollingFileAppender log4j.appender.A2.MaxFileSize=10MB log4j.appender.A2.MaxBackupIndex=1 log4j.appender.A2.layout=org.apache.log4j.TTCCLayout log4j.appender.A2.layout.ContextPrinting=enabled log4j.appender.A2.layout.DateFormat=ISO8601 # Root category set to DEBUG using the A2 appender defined above.

# ルートのカテゴリは、上記で定義されたA2のアペンダを使い、DEBUGに設定します。

log4j.rootCategory=DEBUG, A2 # Category definitions:

# カテゴリの定義:

# The SECURITY category inherits is priority from root. However, it's output # will go to A1 appender defined above. It's additivity is non-cumulative.

# SECURITYカテゴリは、ルートからの優先度を継承します。しかし、その出力は、 # 上記で定義されたA1のアペンダに対して行います。その加法は、累積ではありません。

log4j.category.SECURITY=INHERIT, A1 log4j.additivity.SECURITY=false # Only warnings or above will be logged for the category "SECURITY.access".

# 警告と上記のものだけがカテゴリ "SECURITY.access"へログ出力されます。

# Output will go to A1.

# 出力は、A1に対して行います。

log4j.category.SECURITY.access=WARN # The category "class.of.the.day" inherits its priority from the # category hierarchy. Output will go to the appender's of the root # category, A2 in this case.

# カテゴリ "class.of.the.day" は、カテゴリ階層から優先度を継承します。 # 出力は、ルートのカテゴリのアペンダに対して行います。この場合は、A2になります。

log4j.category.class.of.the.day=INHERIT

Refer to the setOption method in each Appender and Layout for class specific options.

クラス設定オプションに関しては、各アペンダとレイアウトの setOptionを参照してください。

Use the # or ! characters at the beginning of a line for comments.

コメント行の始めは、#または!文字を使います。

パラメータ:
configFileName - The name of the configuration file where the configuration information is stored.

configFileName 設定情報が保存されている設定ファイルの名前


configure

public static void configure(String configFilename)

configure

public static void configure(URL configURL)
Read configuration options from url configURL.

url configURL から設定オプションを読み込みます。

導入されたバージョン:
0.8.2

configure

public static void configure(Properties properties)
Read configuration options from properties.

propertiesから設定オプションを読み込みます。

See doConfigure(String, Hierarchy) for the expected format.

求められるフォーマットに関しては、doConfigure(String, Hierarchy) を参照してください。


configureAndWatch

public static void configureAndWatch(String configFilename)
Like configureAndWatch(String, long) except that the default delay as defined by FileWatchdog.DEFAULT_DELAY is used.

デフォルトの FileWatchdog.DEFAULT_DELAYで定義される遅延時間が 利用されることを除いて、configureAndWatch(String, long) と同様です。

パラメータ:
configFilename - A file in key=value format.

configFilename key=valueフォーマットをもつファイル


configureAndWatch

public static void configureAndWatch(String configFilename,
                                     long delay)
Read the configuration file configFilename if it exists. Moreover, a thread will be created that will periodically check if configFilename has been created or modified. The period is determined by the delay argument. If a change or file creation is detected, then configFilename is read to configure log4j.

もし存在すれ場合は、設定ファイル configFilename を読み込みます。 その上、configFilenameが作成または修正された場合、 定期的にチェックするスレッドが作成されます。 周期は、delay引数により決定します。 もし、変更またはファイル作成が行われた場合、 configFilenameが、log4jを設定するために読み込まれます。

パラメータ:
configFilename - A file in key=value format.

configuFilename key=value フォーマットをもつファイル

delay - The delay in milliseconds to wait between each check.

delay 各チェックを行っている間に待つ、ミリ秒で指定される遅延時間


doConfigure

public void doConfigure(Properties properties,
                        Hierarchy hierarchy)
Read configuration options from properties.

propertiesから設定オプションを読み込みます。

See doConfigure(String, Hierarchy) for the expected format.

求められるフォーマットに関しては、doConfigure(String, Hierarchy) を参照してください。


doConfigure

public void doConfigure(URL configURL,
                        Hierarchy hierarchy)
Read configuration options from url configURL.

url configURLから設定オプションを読み込みます。

定義:
インタフェース Configurator 内の doConfigure
インタフェース org.apache.log4j.spi.Configurator からコピーされたタグ:
パラメータ:
url - The URL to parse

url 解釈できるURL

hierarchy - The hierarchy to operation upon.

hierarchy オペレーション上の階層


configureCategoryFactory

protected void configureCategoryFactory(Properties props)
Check the provided Properties object for a CategoryFactory entry specified by CATEGORY_FACTORY_KEY. If such an entry exists, an attempt is made to create an instance using the default constructor. This instance is used for subsequent Category creations within this configurator.

CATEGORY_FACTORY_KEYにより指定された CategoryFactoryのエントリ に関する与えられた Propertiesオブジェクトをチェックします。 もし、そのようなエントリが存在する場合は、デフォルトのコンストラクタを 使って、インスタンスを作成しようとします。 このインスタンスは、このコンフィギュレータ内部のサブシーケンスのCategory のインスタンスとして使われます。

関連項目:
parseCatsAndRenderers(java.util.Properties, org.apache.log4j.Hierarchy)

parseCatsAndRenderers

protected void parseCatsAndRenderers(Properties props,
                                     Hierarchy hierarchy)
Parse non-root elements, such non-root categories and renderers.

ルートのカテゴリではないものやレンダラーのようなルートではない要素を 解析します。



Please notify me about new log4j releases.