All,

Java running on windows 2008 r2 against tomcat 7.0.19

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

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.
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 &quot;%r&quot; %s %b"
resolveHosts="false"/>
      </Host>

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" />
        <param name="Append" value="true" />
        <rollingPolicy
class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern"
value="${catalina.base}/logs/demo.%d{yyyy-MM-dd}.log" />
        </rollingPolicy>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %t %X{user} %-5p [%c]
%m%n" />
        </layout>
    </appender>

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 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

Has anyone else done this? I can't believe that we are unique. Perhaps I am
just ignorant of the correct term to search for. Any help greatly
appreciated

Thanks

Chris

Reply via email to