English 中文(简体)
Overriding log4j settings at deploy time
原标题:

For an application which is deployed on a large number of machines I took the decision to deploy a standard log4j.xml file with the application package, just to make sure that have the same settings are present everywhere : appenders, categories, levels.

This does have the downside that when modifying the levels locally we risk losing the changes on re-deploy or living with old settings. In practice, the only thing we need to change are the logger levels, most of the time 1 of them, so I m looking for a solution which allows me to override just the levels per-installation.

How can I override the log4j levels without changing the original log4j.xml file?

最佳回答

If you still want to have a shared main configuration, you could consider adding something to the application that allowed the Log4J logger levels to be changed after initialization. You could invoke these changes either via JMX, getting the overrides from a centralized source, or simply by periodically reading a local installation-specific override file (if present), depending on what infrastructure support your application can rely on.

Take a look at this for some more information:

问题回答

Set the environment variable log4j.configuration to point to an external file. This way if you re-deploy, the external file is no touched or changed and therefore your configuration is not lost.

For reference, see the Default Initialization Procedure section in the log4j manual.

I used to solve such problems by introducing another indirection into log4j properties file. For example specifying like

log4j.appender.CONSOLE.Threshold = %level%.

At run time, first thing I was doing is replacing the placeholders in memory, or sticking in the defaults. This way log4j configuration never changed throughout all deployments, including developers, QA and even production. Every target would have its main set of configuration parameters, amongst them would be %placeholders% for the level. These parameters would either come with the installer, or each user would keep main configuration aside while pulling the new version to work with. But log4j configuration never changes and nobody touches is except developers who involved directly with it.

May be my explanation is a bit too complicated... think of it as a Spring PropertyPlaceholderConfigurer and apply it to log4j configuration :)

It s a bit of coding, but really simple and solve lots of problems down the road.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签