airmil
airmil

Reputation: 115

Log4j different .property files for Appenders

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

Upvotes: 2

Views: 158

Answers (2)

Paul Vargas
Paul Vargas

Reputation: 42060

If each version running on a different VM process (on different ports), you can add an argument to the virtual machine. e.g.:

-Dmysystem.version=1.0.1

If you are using the XML configuration:

<param name="file" value="/logs/system.v${mysystem.version}.log" />

Of if you are using the properties:

log4j.appender.ROLL.File=/logs/system.v${mysystem.version}.log

In both cases, the generated file might be:

/logs/system.v1.0.1.log

In this way, you can maintain a single configuration file and dynamic filenames.

Upvotes: 0

anuu_online
anuu_online

Reputation: 384

You can use DOMConfigurator or PropertyConfigurator to load your log4j settings from an external file. You can invoke this API multiple times under a run to load the settings from different sources.

In your case, you can load the Appender details alone dynamically from another property file based on the version.Just like suffixing some version id to the file name and loading it from your code in a generic way.

Upvotes: 1

Related Questions