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? stackoverflow.com/questions/1140358/…Brent Worden– Brent Worden2012-02-27 02:58:09 +00:00Commented Feb 27, 2012 at 2: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– lamwaiman19882012-02-27 04:17:09 +00:00Commented Feb 27, 2012 at 4: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
Comments
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.