You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Eggers <it...@yahoo.com> on 2010/05/05 11:29:43 UTC
Re: Log4j logging doesn't work when a web application is moved outside Tomcat/webapps directory
I just hacked together a quick example on Windows/XP Professional. I imagine it will work the same way on my Linux machine.
Environment:
OS: Windows/XP Professional - all the latest patches
Java: 1.6.0_20 from Sun
Tomcat: 6.0.26
IDE: NetBeans 6.8
I am reworking the Spring Developer's Notebook bike store example, so I can understand Spring testing and using mock objects. I've run into a lot of "interesting" issues, mostly having to do with Spring test libraries versus Junit versus mock objects. However, that's a topic for another discussion.
At any rate, I set up the following system:
Tomcat location: C:\Apache\apache-tomcat-6.0.26
localhost webapps: C:\Apache\apache-tomcat-6.0.26\webapps
foo webapps: C:\Apache\hosts\foo-hosts\webapps
bar webapps: C:\Apache\hosts\bar-hosts\webapps
I like to put my virtual hosts outside of the Tomcat directory tree. That way, when I upgrade Tomcat I don't have to worry about virtual host applications.
Next, I duplicated the <Host></Host> node in server.xml for the foo and bar hosts. The resulting <Host></Host> nodes from my server.xml are shown below.
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="foo" appBase="C:/Apache/hosts/foo-host/webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="bar" appBase="C:/Apache/hosts/bar-host/webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
Note that I didn't change any of the logging prefixes and suffixes, so all common logging gets mixed together. Since this is just a proof of concept, I don't really mind.
Next, I copied manager.xml from conf/Catalina/localhost to conf/Catalina/foo, and conf/Catalina/bar.
I also copied the manager and ROOT web applications to foo-host\webapps and bar-host\webapps (full path above). It's nice to have a generic welcome page on test hosts just to make sure your servers are running. The manager application is useful as well, although I can just copy war files around.
Finally for my setup, I added 127.0.0.1 foo and 127.0.0.1 bar to my hosts file in WINNT\system32\drivers\etc (this is an upgraded Windows/2000 Professional machine).
Upon starting up this mess, all three hosts were visible at localhost:8080, foo:8080, and bar:8080 as you would expect.
I then took the web application, and created three war files. The only difference in each of the war files was the location of the log file. An example is shown below.
### direct messages to file dnb-02.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=${catalina.home}/logs/dnb-02.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=warn, file
### Spring Framework logging
log4j.logger.org.springframework=info
For the other two war files, I just changed dnb-02.log to foo-dnb-02.log and bar-dnb-02.log.
I really should use a different environment variable and pass it in via JAVA_OPTS. That way I can set it easily in my IDE to do testing that will include logging.
I then used the Tomcat manager on all three virtual hosts to load up the appropriate applications.
To test, I caused different warnings to be logged in different virtual hosts, then grepped the logs for the results.
As expected, I got three different log files, and the warnings (along with time stamps) were in the right log files.
Note that I do not have any non-Tomcat jar in apache-tomcat-6.0.26 besides JDBC jars at this point.
Just for completeness - here's the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
Sorry for the formatting.
Hope this helps. I hate to say this . . . it works for me.
/mde/
--- On Tue, 5/4/10, Joe Hansen <jo...@gmail.com> wrote:
> From: Joe Hansen <jo...@gmail.com>
> Subject: Re: Log4j logging doesn't work when a web application is moved outside Tomcat/webapps directory
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Date: Tuesday, May 4, 2010, 4:55 PM
> This thread has grown too long. For
> anyone following this thread,
> here's the summary:
>
> Two web applications, each with a Virtual Host entry in
> server.xml file.
> Tomcat/webapps-abc
> Tomcat/webapps-xyz
>
> These two web applications have different log4j.properties
> files.
> These log4j property files log to different log files
> (Tomcat/logs/abc.log and Tomcat/logs/xyz.log).
> Tomcat/webapps-abc/ROOT/WEB-INF/classes/log4j.properties
> Tomcat/webapps-xyz/ROOT/WEB-INF/classes/log4j.properties
>
> The web applications abc and xyz using Java Commons Logging
> API (Log
> and LogFactory classes) to perform logging.
>
> Scenario 1:
> log4j.jar is in Tomcat/lib directory
> log4j.jar is NOT in WEB-INF/lib directories
>
> Result:
> abc webapp's log entries are written to xyz.log file
>
>
> Scenario 2:
> log4j.jar is NOT in Tomcat/lib directory
> log4j.jar is in WEB-INF/lib directories
>
> Result:
> ClassNotFoundError in Tomcat/logs/catalina.log files
>
>
> Scenario 3:
> log4j.jar is in Tomcat/lib directory
> log4j.jar is in WEB-INF/lib directories
>
> Result:
> Empty abc.log and xyz.log files.
>
>
> Here's the relevant portion of the
> webapps-abc/ROOT/WEB-INF/web.xml file:
> <listener>
>
> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
> </listener>
> <context-param>
>
> <param-name>log4jConfigLocation</param-name>
>
> <param-value>/WEB-INF/classes/log4j.properties</param-value>
> </context-param>
> <context-param>
>
> <param-name>log4jExposeWebAppRoot</param-name>
>
> <param-value>false</param-value>
> </context-param>
> <listener>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> </listener>
>
>
> webapps-xyz/ROOT/WEB-INF/web.xml file looks just the same
>
> /* webapps-abc/ROOT/WEB-INF/classes/log4j.properties */
> log4j.rootLogger=INFO, A2
> log4j.appender.A2=org.apache.log4j.RollingFileAppender
> log4j.appender.A2.layout=org.apache.log4j.PatternLayout
> log4j.appender.A2.layout.ConversionPattern=%d{yyyy MMM dd /
> HH:mm:ss}
> %-5p - [%c] : %m %n
> log4j.appender.A2.File=c:/Tomcat6/logs/abc.log
> log4j.appender.A2.MaxFileSize=100KB
> log4j.appender.A2.MaxBackupIndex=4
>
>
> /* webapps-xyz/ROOT/WEB-INF/classes/log4j.properties */
> log4j.rootLogger=INFO, A1
> log4j.appender.A1=org.apache.log4j.RollingFileAppender
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern=%d{yyyy MMM dd /
> HH:mm:ss}
> %-5p - [%c] : %m %n
> log4j.appender.A1.File=c:/Tomcat6/logs/xyz.log
> log4j.appender.A1.MaxFileSize=100KB
> log4j.appender.A1.MaxBackupIndex=4
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Mark H. Wood [mailto:mwood@IUPUI.Edu]
> Subject: Re: Log4j logging doesn't work when a web application is moved
> outside Tomcat/webapps directory
>
> Maybe because the documentation doesn't say it's improper;
The current documentation for <Context> states (in bold):
"For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place <Context> elements directly in the server.xml file."
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
Posted by "Mark H. Wood" <mw...@IUPUI.Edu>.
On Wed, May 05, 2010 at 08:31:33AM -0500, Caldarale, Charles R wrote:
> As always, don't put <Context> elements in server.xml. The above got you double deployment of the foo webapp, once as foo, once as the default.
>
> Why do people invite problems when it's so easy to do things properly?
Maybe because the documentation doesn't say it's improper; it says you
can do this. Your advice in this matter makes good sense when you
explain it, but nobody sees it until he runs into a problem and brings
it here. I think a documentation update from you would be widely
appreciated, and save you loads of time in the long run.
--
Mark H. Wood, Lead System Programmer mwood@IUPUI.Edu
Balance your desire for bells and whistles with the reality that only a
little more than 2 percent of world population has broadband.
-- Ledford and Tyler, _Google Analytics 2.0_
RE: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Nuno Faria [mailto:nuno.m.faria@gmail.com]
> Subject: Re: Log4j logging doesn't work when a web application is moved
> outside Tomcat/webapps directory
>
> Following this thread and reading the docs I created virtual hosts
> using the same webapps dir
That's a really, really bad idea - the hosts can easily scribble on each other when expanding war files. Don't do it, even in development.
> (it is a development environment with CVS and I would have
> to change many things to accomplish one webapp folder per
> virtual host).
Much better to spend the effort up front to do things the right way than have to always wonder if the cause of strange behavior is due to having an invalid configuration.
> <Context path="" docBase="foo" reloadable="true" />
As always, don't put <Context> elements in server.xml. The above got you double deployment of the foo webapp, once as foo, once as the default.
Why do people invite problems when it's so easy to do things properly?
> <Context path="" docBase="bar" reloadable="true" />
Same comment as above.
> with this I avoid full apps initialization on Tomcat Startup
No, you don't - each app has to be initialized for each <Host> (or in your case, multiple times for each <Host>). All you might have avoided is expanding the .war files, which for development purposes you didn't need in the first place.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
Posted by Nuno Faria <nu...@gmail.com>.
I was having a similar problem moving a Tomcat 5.5 configuration to 6.0.
Following this thread and reading the docs I created virtual hosts
using the same webapps dir (it is a development environment with CVS
and I would have to change many things to accomplish one webapp folder
per virtual host).
Using the examples on this thread it would be like this
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="foo" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="foo" reloadable="true" />
</Host>
<Host name="bar" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="bar" reloadable="true" />
</Host>
with this I avoid full apps initialization on Tomcat Startup (I have
up to 20 and use <!-- --> to comment the Host I am not workin on) and
I am able to treat each app under webapps as an independent host.
I suppose it is not a good set-up for a production environment but I
needed a quick set-up to start working ASAP and this seems to work
just fine.
On Wed, May 5, 2010 at 10:57 AM, André Warnier <aw...@ice-sa.com> wrote:
> That was a nice and concise write-up, well-worth of an article in the Tomcat
> FAQ/WIKI.
> "How to setup Tomcat with 3 virtual hosts, each with its own homepage and
> Manager (and other) applications, and its own logfiles".
>
> My only minor remark :
>
> Mark Eggers wrote:
> ...
>>
>> Finally for my setup, I added 127.0.0.1 foo and 127.0.0.1 bar to my hosts
>> file in WINNT\system32\drivers\etc (this is an upgraded Windows/2000
>> Professional machine).
>>
>> Upon starting up this mess, /***/ all three hosts were visible at
>> localhost:8080, foo:8080, and bar:8080 as you would expect.
>>
> At the /***/, I would insert "from a browser running on the same machine".
> Nothing to do with Tomcat really, but there are still quite a number of
> people out there confused by hostname lookup and IP routing stuff.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: interesting dillemma with
Posted by André Warnier <aw...@ice-sa.com>.
Yucca Nel wrote:
> it would appear that the entity ben that sets the password entered into
> this form tag may not accept a String as it's param as I keep getting
> illegal argument exception. Can anyoe advise on how I rectify?
You could start by not hijacking unrelated threads.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
interesting dillemma with
Posted by Yucca Nel <yu...@live.co.za>.
it would appear that the entity ben that sets the password entered into
this form tag may not accept a String as it's param as I keep getting
illegal argument exception. Can anyoe advise on how I rectify?
--------------------------------------------------
From: "André Warnier" <aw...@ice-sa.com>
Sent: Wednesday, May 05, 2010 11:57 AM
To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
> That was a nice and concise write-up, well-worth of an article in the
> Tomcat FAQ/WIKI.
> "How to setup Tomcat with 3 virtual hosts, each with its own homepage and
> Manager (and other) applications, and its own logfiles".
>
> My only minor remark :
>
> Mark Eggers wrote:
> ...
>>
>> Finally for my setup, I added 127.0.0.1 foo and 127.0.0.1 bar to my hosts
>> file in WINNT\system32\drivers\etc (this is an upgraded Windows/2000
>> Professional machine).
>>
>> Upon starting up this mess, /***/ all three hosts were visible at
>> localhost:8080, foo:8080, and bar:8080 as you would expect.
>>
> At the /***/, I would insert "from a browser running on the same machine".
> Nothing to do with Tomcat really, but there are still quite a number of
> people out there confused by hostname lookup and IP routing stuff.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Log4j logging doesn't work when a web application is moved outside
Tomcat/webapps directory
Posted by André Warnier <aw...@ice-sa.com>.
That was a nice and concise write-up, well-worth of an article in the
Tomcat FAQ/WIKI.
"How to setup Tomcat with 3 virtual hosts, each with its own homepage
and Manager (and other) applications, and its own logfiles".
My only minor remark :
Mark Eggers wrote:
...
>
> Finally for my setup, I added 127.0.0.1 foo and 127.0.0.1 bar to my hosts file in WINNT\system32\drivers\etc (this is an upgraded Windows/2000 Professional machine).
>
> Upon starting up this mess, /***/ all three hosts were visible at localhost:8080, foo:8080, and bar:8080 as you would expect.
>
At the /***/, I would insert "from a browser running on the same machine".
Nothing to do with Tomcat really, but there are still quite a number of
people out there confused by hostname lookup and IP routing stuff.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
Posted by Joe Hansen <jo...@gmail.com>.
Mark, Chuck, Andre, and Charles, You guys rock!
Mark, I followed your recommendations and
1. I copied the virtual host webapps directories outside Tomcat.
c:/hosts/abc.local/webapps
c:/hosts/xyz.local/webapps
2. Copied the manager.xml to Tomcat/conf/Catalina/abc.local and
Tomcat/conf/Catalina/xyz.local. Also copied the manager web
application to c:/hosts/abc.local/webapps and
c:/hosts/xyz.local/webapps
3. I commented the following segment from abc.local/ROOT/WEB-INF/web.xml file
<!--
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
-->
4. Removed log4j.jar from Tomcat/lib directory and copied it to
abc.local/webapps/ROOT/WEB-INF/lib and
xyz.local/webapps/ROOT/WEB-INF/lib
I then restarted Tomcat. This DID NOT solve the issue complete though.
The MOST IMPORTANT step was to move all jar files EXCEPT THE FOLLOWING
jar files to WEB-INF/lib directory from Tomcat/lib directory:
annotations-api.jar
catalina.jar
catalina-*.jar
commons-dbcp.jar
commons-pool.jar
el-api.jar
jasper*.jar
jsp-api.jar
mail.jar
servlet-api.jar
tomcat*.jar
DATABASE-DRIVERS.jar
As previously thought, the Quartz jobs (that run every one hour) were
not part of the problem!
I could not have resolved this issue without your contribution! I am
very grateful for your kind help. :) Thank you all!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Mark Eggers [mailto:its_toasted@yahoo.com]
> Subject: Re: Log4j logging doesn't work when a web application is moved
> outside Tomcat/webapps directory
>
> Note that I do not have any non-Tomcat jar in apache-tomcat-6.0.26
> besides JDBC jars at this point.
Which I suspect is key to solving the OP's problem.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Log4j logging doesn't work when a web application is moved
outside Tomcat/webapps directory
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Mark Eggers [mailto:its_toasted@yahoo.com]
> Subject: Re: Log4j logging doesn't work when a web application is moved
> outside Tomcat/webapps directory
>
> I just hacked together a quick example on Windows/XP Professional.
> > That was a nice and concise write-up, well-worth of an article
> > in the Tomcat FAQ/WIKI.
I strongly second André's comment. If it's not possible for you to put this in the FAQ, may one of us do it for you?
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org