views:

57

answers:

1

Hi All

Requirement is this ...

One question, The usual place seems to be in your /WEB-INF/classes directory, but I have problems with that.if I ship my application as a WAR file, I can't get at it to edit it, which is a real problem.

We have our 3 WAR, we deployed apps with tomcat 6.0.16. We want to configure log4j.xml in external dir for each war and loaded from there dynamically.

I really dont want to use "-Dlog4j.configuration=/Directory/log4j.xml" this env setting as a solution. Because it will become default not WAR specific.

Any suggestions? Any Help Appreciated ...

+1  A: 

I know you mention that you don't want to use the start-up parameter "-Dlog4j.configuration=/Directory/log4j.xml" but have you considered using a custom parameter like

-DappOneLog4jConfig=/directoy/file1.xml
-DappTwoLog4jconfig=/directory/file2.xml

And then in each of your war files you can load the log4j file you want. You can do something like this in a class that gets loaded at startup.

if(System.getProperty("appOneLog4jConfig") != null){
      PropertyConfigurator.configure(System.getProperty("appOneLog4jConfig"));
} else {
      BasicConfigurator.configure();
      Logger.getRootLogger().setLevel(Level.INFO);
}

which says if I have a property file specified, use that. otherwise default everything to Info. This should give you the freedom to set a log4j file for each application/war file

Sean
yeah.I know it works fine, but what is the common best practice for log4j config for multiple webapps. What I really want is I have webapp specific log4j.xml packed in my wars (without appender), and common log4j.xml is placed @ tomcat level with a appender, when a webapp1 log came it should be logged with app1.log and for second it should be logged with app2.log. I have context.xml for each webapp is there a way i can set a param for app specific value and get the value in top level log4j.xml like this "<param name="File" value="${catalina.home}/logs/${webapp-name}/warn.log"/>" ?????
bubesh