1

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?

lamwaiman1988
  • 3,729
  • 15
  • 55
  • 87

2 Answers2

2

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

Jayan
  • 18,003
  • 15
  • 89
  • 143
1

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.

bmargulies
  • 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
  • Call System.setProperty before initializing any loggers. – bmargulies Feb 27 '12 at 15:15