I know we can put it in the home directory of the project and it works as a charm. But really I want to put it under a directory name "Conf" for convenience of later maintenance. How can we do this?
-
is this answer helpful? http://stackoverflow.com/questions/1140358/how-to-initialize-log4j-properly – Brent Worden Feb 27 '12 at 02:58
-
Actually I don't want to do it in the Java commandline...I would prefer a way to include it in the java program. – lamwaiman1988 Feb 27 '12 at 04:17
2 Answers
log4j gives option to use different file as input. Also you can do a watch on the contents. See http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html#configureAndWatch(java.lang.String, long) for details

- 18,003
- 15
- 89
- 143
I don't know about 'we', but the log4j documentation is perfectly clear.
http://logging.apache.org/log4j/1.2/manual.html will tell you that log4j searches for log4j.properties or log4j.xml in the classpath, until and unless you use a system property to tell it to look for a different file or in a different place.
You might also find http://robertmaldon.blogspot.com/2007/09/programmatically-configuring-log4j-and.html interesting as an example of explicit configuration from code; it does not use a log4j.properties At All.

- 97,814
- 39
- 186
- 310
-
Yes, what I am asking is how to tell log4j to look for a different place for the properties file. I think if we include the directory into the classpath it would be fine, but I don't want to do it as a run option for "Java". – lamwaiman1988 Feb 27 '12 at 04:19
-