I was wondering if there is a way to define the appenders (file, console etc) on a different file than the one defining the actual logging properties. The idea came up from a system I am developing and we have the following requirement: Different versions of the system will be deployed on the same server. So in order not to maintain different log4j properties file, that will all set the same properties and differ on the file appenders (so as to know which log was recorded from which version of the system). Thank you in advance
2 に答える
1
DOMConfigurator または PropertyConfigurator を使用して、外部ファイルから log4j 設定をロードできます。実行中にこの API を複数回呼び出して、さまざまなソースから設定を読み込むことができます。
あなたの場合、バージョンに基づいて別のプロパティ ファイルからアペンダーの詳細だけを動的に読み込むことができます。ファイル名にバージョン ID を付けて、一般的な方法でコードから読み込むのと同じです。
于 2013-10-13T12:57:26.707 に答える
0
各バージョンが異なる VM プロセス(異なるポート) で実行されている場合は、仮想マシンに引数を追加できます。例えば:
-Dmysystem.version=1.0.1
XML 構成を使用している場合:
<param name="file" value="/logs/system.v${mysystem.version}.log" />
プロパティを使用している場合:
log4j.appender.ROLL.File=/logs/system.v${mysystem.version}.log
どちらの場合も、生成されるファイルは次のようになります。
/logs/system.v1.0.1.log
このようにして、単一の構成ファイルと動的ファイル名を維持できます。
于 2013-10-15T12:58:37.380 に答える