1

Is it possible to configure the log4j log level using an external configuration file? Rather than have a user configure the log level in the log4j.properties file, I would like them to configure the log level using a project configuration file.

WulfgarPro

1
  • Do you plan to re-deploy your app after the log4j settings have been updated by the user? Otherwise log4j will not pick up those changes. Commented Mar 28, 2011 at 4:56

1 Answer 1

2

That depends on your build/make tool. For example: in Maven I do just that. In Maven there is "filtering" feature that you can enable. Maven filtering will replace ${some_property} in all your resource files with whatever the value of "some_property" is in Maven.

That is how I change my Log4J properties if I am in dev or prod mode. Other than that, I dont know if Log4J itself has such a feature. I am sure the same is possible via Ant.

Sign up to request clarification or add additional context in comments.

6 Comments

@somid3, I can extract the property with Ant .. but how do I insert it into my log4j.properties file?
I just goggled this and haven't used it ant filtering. It seems the ant notation is to surround the value with @s. Your Log4J props file would like: property_name = @some_value@ where "some_value" is defined in your build.xml
@somid3 - i'm not sure how the Filter task has anything to do with my problem. My current thought process is to remove the log4j.properties file and setup the logging level programmatically via the key-value project configuration file.
Filter is good for when you want to pass a global value to a properties file. For example your log4j.properties will have a line "log4j.rootCategory=@level@" and you can define "level" in Ant. Your project configuration will define the value for "level" and Ant will replace @level@ in your log4j.properties file -- I think that is your question, otherwise can you clarify your situation?
@somid3 - filter works. Thanks! I added something like so: <filter token="LOG-LEVEL" value=${LOGGING}. The LOGGING variable comes from my properties file and LOG-LEVEL is defined within log4j.properties like so: @LOG-LEVEL@.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.