On 22/11/2011 22:35, Christopher Schultz wrote: > Chris, > > On 11/22/11 2:28 PM, chris derham wrote: >> Java running on windows 2008 r2 against tomcat 7.0.19 java version >> "1.6.0_24" > > Thanks! > >> I have a single war file, and would like to host multiple demo >> sites of our app. So ideally users access demo1.company.com and >> demo2.company.com. Completely isolated, but all running the same >> war. Please correct me where ever my logic is wrong, but I figured >> that I would > >> 1) have a tomcat instance, containing config directory. This would >> have catalina/demo1.company.com/ROOT.xml containing pertinent jndi >> config. > > Sounds good. > >> 2) in server.xml add this > >> <Host name="demo1.company.com" appBase="webapps\demos" >> unpackWARs="false" autoDeploy="false"> <Valve >> className="org.apache.catalina.valves.AccessLogValve" >> directory="logs" prefix="demo_access_log." suffix=".log" >> pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/> >> </Host> > > Well, that will give you an access log for the whole host. If that's > what you want, that's what you got. If you want the webapps to have > separate access logs, you'll have to configure the <Valve> in ROOT.xml > (and whatever other webapps you deploy). Maybe something like > "ROOT-access" as the "prefix" value. > >> When I start the app, it works and the app works. However all >> context's apps log to the same log file. What I want to know how to >> make the different contexts under different hosts log to different >> file. Our log4j file contains > >> <appender name="FILE" >> class="org.apache.log4j.rolling.RollingFileAppender"> <param >> name="Threshold" value="INFO" /> <param name="File" >> value="${catalina.base}/logs/demo.log" /> > > So, this is a different issue. Above, you had an access log, which > logs the hosts and URLs that they request, etc. > > It appears that log4j is an application log, like for INFO and DEBUG > and stuff like that, right? > > Well, the obvious solution is to change the value of the "File" > parameter in your log4j configuration. Try using something like > "ROOT-demo.log" and a different value in the config file for the other > copies that you deploy. Of course, that means that you can't actually > use the same WAR file, or you need to figure out some way to load the > log4j configuration file from another location. > > If you write your own ServletContextListener to load the log4j > configuration (that's what we do over here... it also shuts-down log4j > when the webapp undeploys), then you ought to be able to use the JNDI > context to find the location of a configuration file on a per-context > basis. For instance, you could put your config files somewhere like > /etc/mywebapp/ROOT.xml and /etc/mywebapp/non-root.xml and just change > the name of the log file name. > > (which does stuff like log the > >> I have searched around, and found some references to JNDI context >> selectors for log4j, but I believe that this is to allow log4j >> separation - not directly related to what I am trying to do. > > I'm afraid I don't know a thing about JNDI context selectors and > log4j. Sorry. > >> I have tried to add a suitable web.xml environment entry, and then >> add it to the log file name, e.g. >> ${catalina.base}/logs/${tomcatInstancePrefix}demo.log. Then in >> ROOT.xml for each host I add > >> <Environment name="tomcatInstancePrefix" value="demo2-" >> type="java.lang.String" override="false"/> > >> and in web.xml I add > >> <resource-env-ref> >> <resource-env-ref-name>tomcatInstancePrefix</resource-env-ref-name> > > > <resource-env-ref-type>java.lang.String</resource-env-ref-type> >> </resource-env-ref> > >> but that didn't work > > Yeah, that doesn't work because it doesn't set a system property, > which is what log4j requires for that kind of replacement.
You could just run separate instances of Tomcat. It would be less hassle & easier to manage. Separate CATALINA_HOME & CATALINA_BASE, so you can use the same core code & just create some separate instances. p -- [key:62590808]
signature.asc
Description: OpenPGP digital signature