tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allistair Crossley" <Allistair.Cross...@QAS.com>
Subject RE: Tomcat 5.5 upgrade + logging problems
Date Fri, 12 Aug 2005 14:32:33 GMT
===================================================================================
Tomcat 5.5.10 Virtual Host example setup with log4j logging per host
===================================================================================

I hope this can be of some use to those who are confused about how to add logging to Virtual
Hosts in Tomcat 5.5 Series since the disappearance of FileLogger.

You will need to be able to configure DNS resolution for this example.

In this example I setup 2 Virtual Hosts each with their own web applications. Each
host gets its own log.

I cause an exception in one of the Virtual Hosts to show that its logging is directed
into its log.

Virtual Host DNS Entries
------------------------

Create 2 DNS entries to the Tomcat target machine

tomcata.qas.com
tomcatb.qas.com

Tomcat 5.5.10
-------------

Download and unzip somewhere.

Virtual Host Web Applications
-----------------------------

Create directories for the vhost webapps

catalina_home/webapps-a
catalina_home/webapps-b

Copy ROOT and jsp-examples directories from catalina_home/webapps into both webapps-a and
webapps-b

Setup the exception test
------------------------

Enter webapps-b/jsp-examples
Create file test.jsp and add into it

<% throw new Exception(); %>

log4j.properties
----------------

Create file log4j.properties in catalina_home/common/classes and copy the following into it;

# Root
log4j.rootCategory=error, R

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=c:/jakarta-tomcat-5.5.10/logs/tomcat-root.log
log4j.appender.R.MaxFileSize=1500KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d - %5p (%C:%L) - %m%n

# VH A
log4j.appender.A=org.apache.log4j.RollingFileAppender
log4j.appender.A.File=c:/jakarta-tomcat-5.5.10/logs/tomcat-a.log
log4j.appender.A.MaxFileSize=1500KB
log4j.appender.A.MaxBackupIndex=1
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%d - %5p (%C:%L) - %m%n

# VH B
log4j.appender.B=org.apache.log4j.RollingFileAppender
log4j.appender.B.File=c:/jakarta-tomcat-5.5.10/logs/tomcat-b.log
log4j.appender.B.MaxFileSize=1500KB
log4j.appender.B.MaxBackupIndex=1
log4j.appender.B.layout=org.apache.log4j.PatternLayout
log4j.appender.B.layout.ConversionPattern=%d - %5p (%C:%L) - %m%n

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=false

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[tomcata.qas.com]=DEBUG, A
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[tomcata.qas.com]=false

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[tomcatb.qas.com]=DEBUG, B
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[tomcatb.qas.com]=false

server.xml
----------

After the localhost Host element, add the Virtual Hosts (here I also add per Host access logs)

<Host name="tomcata.qas.com" appBase="webapps-a">
  <Valve 
    className="org.apache.catalina.valves.FastCommonAccessLogValve"
    directory="logs"  
    prefix="a_access_log." 
    suffix=".txt"                
    pattern="common" 
    resolveHosts="false"/> 
</Host>

<Host name="tomcatb.qas.com" appBase="webapps-b">
  <Valve 
    className="org.apache.catalina.valves.FastCommonAccessLogValve"
    directory="logs"  
    prefix="b_access_log." 
    suffix=".txt"                
    pattern="common" 
    resolveHosts="false"/> 
</Host>  

logging jars
------------

Download and copy log4j1.2.9.jar into catalina_home/common/lib
Download and copy commons-logging.jar into catalina_home/common/lib

Finish and Test
---------------

That's it. Start Tomcat and go into the logs directory. You should see all the new logs created
with some default startup information. 

Now browse to 

http://tomcata.qas.com:8080/ (you should get the ROOT tomcat welcome page)
http://tomcatb.qas.com:8080/test.jsp (you should get an exception, check the tomcat-b.log

Summary
-------

Note that this is virtual host logging, it is not webapp logging. For webapp logging you need
to configure log4j within the web application itself which is another example.

-- end --

> -----Original Message-----
> From: Allistair Crossley 
> Sent: 12 August 2005 13:57
> To: tomcat-user@jakarta.apache.org
> Cc: Robert Abbate
> Subject: RE: Tomcat 5.5 upgrade + logging problems
> 
> 
> Hi Robert,
> 
> The fact is that followed precisely the instructions do work. 
> I *almost* guarantee this because I walked through it just 
> last week with a guy on a vanilla Tomcat 5.5.9 install and I 
> deal with Tomcat and logging daily.
> 
> The question is, what kind of logging do you want, because 
> there are 2 types. The old FileLogger was internal logging 
> mixed with webapp logging. Tomcat 5.5 aims to decouple itself 
> from a custom logging implementation and uses the Commons 
> Logging wrapper to allow developers to customise their 
> logging output in a more flexible and powerful way. 
> 
> Therefore the developers did not do a *bad thing* as you 
> describe, you are simply peeved off that you don't understand 
> the change. That's natural, noone likes change, but change is 
> inevitable if we are to do things better. Granted that 
> FileLogger was probably easier, but it was not as powerful or 
> flexible. And perhaps the logging page is not the most 
> straightforward but it does work when followed.
> 
> So now, if you want Tomcat core classes logging, i.e internal 
> Tomcat logging, then you need to have a log4j.properties file 
> inside tomcat/common/classes and *both* the log4j jar *and* 
> commons logging jar in tomcat/common/lib. This information in 
> my view is not all that useful unless you're trying to get to 
> the nitty gritty of what's happening. More than likely you 
> are more interested in per-webapp logging.
> 
> If you want logging for a web application in particular, then 
> you need a log4j.properties in the webapp's classes folder 
> and log4j jar only in the lib.
> 
> History on this list shows us that logging configuration 
> issues like these are almost always caused by something the 
> user has misunderstood or done in their "customisation" or 
> web application. 
> 
> As for the multiple virtual hosts with webapps;
> 
> log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina]
> .[localhost][/yourwebappname]=DEBUG, R
> 
> You'll recognise localhost is a servername, so perhaps you 
> could try using your virtual host name and let us know if that works.
> 
> Cheers, Allistair.
> 
> > -----Original Message-----
> > From: Robert Abbate [mailto:director@ispconcepts.com]
> > Sent: 12 August 2005 01:37
> > To: Allistair Crossley
> > Subject: RE: Tomcat 5.5 upgrade + logging problems
> > 
> > 
> > I appreciate your response, but I can assure you there are 
> > many out there
> > which are not able to get this going EVEN after following the scant
> > instructions. I had consulted at least 5 other webhosting 
> > companies that I
> > am in contact with all having the same issue. There is 
> > something wrong and
> > not much help so far. Tomcat developers did a bad thing by 
> > removing support
> > for Logger element. They didn't have to do that since it 
> worked fine.
> > 
> > Also, I see your site doesn't address a virtual /multiple 
> host setup; I have
> > not seen any help anywhere on this setup as we are requesting.
> > 
> > 
> > -----Original Message-----
> > From: Allistair Crossley [mailto:Allistair.Crossley@QAS.com]
> > Sent: Friday, August 12, 2005 3:07 AM
> > To: Tomcat Users List
> > Subject: RE: Tomcat 5.5 upgrade + logging problems
> > 
> > 
> > Really, this has been discussed to death on this mailing 
> list. The 5.5
> > logging page for a start gives you instructions for setting 
> > logging up.
> > Also, I have a blog at www.adcworks.com/blog that touches on 5.5
> > configuration and logging.
> > 
> > Allistair.
> > 
> > > -----Original Message-----
> > > From: Robert Abbate [mailto:director@ispconcepts.com]
> > > Sent: 11 August 2005 15:43
> > > To: tomcat-user@jakarta.apache.org
> > > Subject: Tomcat 5.5 upgrade + logging problems
> > >
> > >
> > > Hi. I have searched through archives and online for such
> > > solutions for the
> > > depreciated "<Logger" element. We have a virtual host setup
> > > and requires
> > > separate logs for each host. We have followed the
> > > instructions such as this:
> > >
> > > jakarta.apache.org/tomcat/tomcat-5.5-doc/logging.html
> > >
> > > we've put log4j.properties file in each host's
> > > WEB-INF/classes folder, and
> > > log4j1.2.8.jar into WEB-INF/lib in each host
> > >
> > > still, nothing seems to work. there must be something we 
> > are missing.
> > >
> > >
> > > CONFIGURATION:
> > >
> > > CATALINA_HOME="/var/tomcat5"
> > > TOMCAT_USER="apache"
> > > JAVA_HOME="/usr/java"
> > > CATALINA_OPTS="-Xmx1228M -Djava.awt.headless=true"
> > >  java= 1.5.0_03
> > >
> > > server.xml
> > > ....CUT....
> > > <Host name="domain.com" unpackWARs="true" autoDeploy="true"
> > > appBase="/home/rondelli/html">
> > >   <Realm className="org.apache.catalina.realm.MemoryRealm"
> > > pathname="/var/tomcat5/conf/tomcat-users/rondelli-t
> > > omcat-users.xml"/>
> > >   <Context path="" docBase="/home/rondelli/html" debug="0"/>
> > > <Alias>www.domain.com</Alias>
> > > <Context path="/tomcatmanager"
> > > docBase="/var/tomcat5/server/webapps/manager"
> > > debug="0" privileged="true"/>
> > >      <Logger className="org.apache.catalina.logger.FileLogger"
> > > prefix="domain.com_log." suffix=".txt" directo
> > > ry="/home/rondelli" timestamp="true"/>
> > > </Host>
> > >
> > > <Host name="domain2.com" unpackWARs="true" autoDeploy="true"
> > > appBase="/home/revisionten/html">
> > >   <Realm className="org.apache.catalina.realm.MemoryRealm"
> > > pathname="/var/tomcat5/conf/tomcat-users/revisionte
> > > n-tomcat-users.xml"/>
> > >   <Context path="" docBase="/home/revisionten/html" debug="0"/>
> > > <Alias>www.domain2.com</Alias>
> > > <Context path="/tomcatmanager"
> > > docBase="/var/tomcat5/server/webapps/manager"
> > > debug="0" privileged="true"/>
> > >      <Logger className="org.apache.catalina.logger.FileLogger"
> > > prefix="domain2.com_log." suffix=".txt" dire
> > > ctory="/home/revisionten" timestamp="true"/>
> > > </Host>
> > > ....CUT.....
> > >
> > >
> > > /usr/java/bin/java
> > > -Djava.util.logging.manager=org.apache.juli.ClassLoaderLo
> > > gManager -Xmx1228M -Djava.awt.headless=true
> > > -Djava.endorsed.dirs=/var/tomcat
> > > 5/common/endorsed -classpath
> > > :/var/tomcat5/bin/bootstrap.jar:/var/tomcat5/bin/commons-loggi
> > > ng-api.jar:/us
> > > r/java/jre/lib/mysql-connector-java-3.0.15-ga-bin.jar:/var/tom
> > > cat5/common/li
> > > b/log4j-1.2.8.jar -Dcatalina.base=/var/tomcat5
> > > -Dcatalina.home=/var/tomcat5
> > > -Djava.io.tmpdir=/var/tomcat5/temp
> > > org.apache.catalina.startup.Bootstrap
> > > start
> > >
> > > Does anyone have a setup like this and can offer any clues?
> > > If you need any
> > > further config details, please ask. I hope I gave all necessary.
> > >
> > >
> > > 
> > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: 
> tomcat-user-help@jakarta.apache.org
> > >
> > >
> > 
> > 
> > <FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE>
> > -------------------------------------------------------
> > QAS Ltd.
> > Registered in England: No 2582055
> > Registered in Australia: No 082 851 474
> > -------------------------------------------------------
> > </FONT>
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > 
> > 
> > 
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message