tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chris derham <>
Subject Single war file - multiple hosts - can't get log4j to log to different files
Date Tue, 22 Nov 2011 19:28:28 GMT

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 and
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/ containing pertinent jndi config.
2) in server.xml add this

      <Host name="" appBase="webapps\demos"
unpackWARs="false" autoDeploy="false">
        <Valve className="org.apache.catalina.valves.AccessLogValve"
               prefix="demo_access_log." suffix=".log"
               pattern="%h %l %u %t &quot;%r&quot; %s %b"

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

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


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



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message