You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Lukas Hazlehurst <lu...@xtra.co.nz> on 2003/06/05 13:18:34 UTC

Having LinkageError trouble with log4j under multiple contexts on Tomcat 4.04

Hello,

I've been using log4jfor a while now in a fairly basic way (using chainsaw)
and it has been fantastic.

My problem now is that i have several identical servlets running under
tomcat which need to log with different configurations. The problem (a
common one i believe) is that only the first context is working properly,
the second is either silently ignored (if log4j configures itself using the
default /classes/lo4j.properties file) or throws up some strange problems
(more on this in a second).

I've found this reference to what i think is the same  problem i am having,
http://marc.theaimsgroup.com/?l=log4j-user&m=105284179922171&w=2 . I have
built and deployed the servlet context listener as described. The context
listeners work fine, i can trace them starting up and stopping properly. The
first context loads properly and gets configured nicely, however the second
context throws a LinkageError error referring to the 'ErrorHandler' class
when it tries to configureAndWatch(). The application then shuts down after
the LinkageError.

Both contexts will run fine if the other is removed from the server, so i
know that both contexts _should_ work. I have tried moving the log4j jar and
the context listener jar around into the tomcat lib directory and so on
(which hasn't helped) but the target server is an ISP server so i don't
really have that option anyhow.

If anyone has any pointers or something that i've missed, it would be a
great help.

Log4j: current cvs
Tomcat: 4.04

Lukas
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.471 / Virus Database: 269 - Release Date: 10/04/2003


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


RE: Having LinkageError trouble with log4j under multiple contexts on Tomcat 4.04

Posted by Lukas Hazlehurst <lu...@xtra.co.nz>.
Jacob,

> I have tested these context listeners with multiple contexts and
> they work
> fine.  However, I'd only tested on Tomcat-4.1.xx, not 4.0.xx.
> Not sure if
> that makes a difference? Try doing the following...

Unfortunately this target (in this case) is 4.04 so i'm stuck there :(

>
> 1.  copy log4j-1.2.8.jar (or latest CVS, I guess) to
> CATALINA_HOME/common/lib (or equivalent in Tomcat-4.0.xx).  I would just
> say shared/lb, but commons-logging seems to barf a bit when that is
> done.  Since Tomcat requires commons-logging, we'll try to play nice by
> adding the logj4 jar file to common/lib instead of shared/lib where I'd
> prefer to put custom jars.
> 2.  copy the selector jar file to CATALINA_HOME/shared/lib (or
> common/lib,
> but I'd avoid putting many custom jars there)
> 3.  copy the servlet jar to WEB-INF/lib of each webapp you are deploying
> 4.  set up context init parameters in each webapp's web.xml
> 5.  set up env-entry if using the ContextJNDISelector and make sure the
> env-entry-value is unique for each webapp
>

Ok, this worked ! I think that previously i had not placed the selector jar
in the common/lib directory, just the log4j jar.

>
> If you have problems with that, let me know.  It think the issue is that
> you have been putting the servlet jar in locations other than the
> WEB-INF/lib of each webapp.  I must stress that no matter what,
> the servlet
> jar *must* be under WEB-INF/lib no matter what.  Once that is done, the
> log4j jar and the selector jar must be in the same classloader so you can
> put these two jars in either WEB-INF/lib (somewhat defeats the purpose of
> this technique, but works...see below....) or a combination of common/lib
> and shared/lib (see comments above and note that common/lib and
> shared/lib
> can see each other so, they are, in effect, the same classloader).

Thanks - this clears up some of the classloader confusion for me. i didn't
realise that the log4j and selector jars had to be within the same
classloader, i figured that since the selector was really part of the app it
should go in the webapp WEB-INF/lib directory.

I'm still not clear why it would work the first time and then get a linkage
error on the second time though ?

>
> Alternatively, you can always just put all the jars in
> WEB-INF/lib of each
> webapp.  This provides you with exactly the same configuration
> options, but
> is kind of overkill since it creates a new logger repository when the
> default one would already be unique.  But, the configuration options are
> worth doing this, I think.  Your app won't know the difference.
> Of course,
> you can forget about the custom selector and listeners and just put
> log4j.jar in each webapp's WEB-INF/lib and either rely on default
> configuration or perform your own.

This was my original approach given that i'm deploying onto host servers
that i do not have much control over. But i was still getting this problem
with secondary contexts. It may be something about how i have my dev server
setup, i'll have to look into this.

Thanks a ton for your help,
Lukas


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.487 / Virus Database: 286 - Release Date: 1/06/2003


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


Re: Having LinkageError trouble with log4j under multiple contexts on Tomcat 4.04

Posted by Jacob Kjome <ho...@visi.com>.
Hi Lukas,

I have tested these context listeners with multiple contexts and they work 
fine.  However, I'd only tested on Tomcat-4.1.xx, not 4.0.xx.   Not sure if 
that makes a difference? Try doing the following...

1.  copy log4j-1.2.8.jar (or latest CVS, I guess) to 
CATALINA_HOME/common/lib (or equivalent in Tomcat-4.0.xx).  I would just 
say shared/lb, but commons-logging seems to barf a bit when that is 
done.  Since Tomcat requires commons-logging, we'll try to play nice by 
adding the logj4 jar file to common/lib instead of shared/lib where I'd 
prefer to put custom jars.
2.  copy the selector jar file to CATALINA_HOME/shared/lib (or common/lib, 
but I'd avoid putting many custom jars there)
3.  copy the servlet jar to WEB-INF/lib of each webapp you are deploying
4.  set up context init parameters in each webapp's web.xml
5.  set up env-entry if using the ContextJNDISelector and make sure the 
env-entry-value is unique for each webapp


If you have problems with that, let me know.  It think the issue is that 
you have been putting the servlet jar in locations other than the 
WEB-INF/lib of each webapp.  I must stress that no matter what, the servlet 
jar *must* be under WEB-INF/lib no matter what.  Once that is done, the 
log4j jar and the selector jar must be in the same classloader so you can 
put these two jars in either WEB-INF/lib (somewhat defeats the purpose of 
this technique, but works...see below....) or a combination of common/lib 
and shared/lib (see comments above and note that common/lib and shared/lib 
can see each other so, they are, in effect, the same classloader).

Alternatively, you can always just put all the jars in WEB-INF/lib of each 
webapp.  This provides you with exactly the same configuration options, but 
is kind of overkill since it creates a new logger repository when the 
default one would already be unique.  But, the configuration options are 
worth doing this, I think.  Your app won't know the difference.  Of course, 
you can forget about the custom selector and listeners and just put 
log4j.jar in each webapp's WEB-INF/lib and either rely on default 
configuration or perform your own.

Jake

At 11:18 PM 6/5/2003 +1200, you wrote:
>Hello,
>
>I've been using log4jfor a while now in a fairly basic way (using chainsaw)
>and it has been fantastic.
>
>My problem now is that i have several identical servlets running under
>tomcat which need to log with different configurations. The problem (a
>common one i believe) is that only the first context is working properly,
>the second is either silently ignored (if log4j configures itself using the
>default /classes/lo4j.properties file) or throws up some strange problems
>(more on this in a second).
>
>I've found this reference to what i think is the same  problem i am having,
>http://marc.theaimsgroup.com/?l=log4j-user&m=105284179922171&w=2 . I have
>built and deployed the servlet context listener as described. The context
>listeners work fine, i can trace them starting up and stopping properly. The
>first context loads properly and gets configured nicely, however the second
>context throws a LinkageError error referring to the 'ErrorHandler' class
>when it tries to configureAndWatch(). The application then shuts down after
>the LinkageError.
>
>Both contexts will run fine if the other is removed from the server, so i
>know that both contexts _should_ work. I have tried moving the log4j jar and
>the context listener jar around into the tomcat lib directory and so on
>(which hasn't helped) but the target server is an ISP server so i don't
>really have that option anyhow.
>
>If anyone has any pointers or something that i've missed, it would be a
>great help.
>
>Log4j: current cvs
>Tomcat: 4.04
>
>Lukas
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.471 / Virus Database: 269 - Release Date: 10/04/2003
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org