tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Jung <>
Subject Re: Log4j per context admin managable configs?
Date Fri, 07 Oct 2011 01:50:05 GMT
On 07.10.2011 03:12, Ilya Kazakevich wrote:
> Hello,
> My app uses log4j. I have several apps running in my tomcat 6 in different
> contexts. I want to log them to different files but filenames (as well as
> levels and even appenders) should be configurable by admin.
> Something like this:
> ./config/ENGINE_NAME/HOST_NAME/ContextName/
> I can't put log4j directly in tomcat so all apps would use one config (and
> it is not what I want).
> I can't put a copy to the each .war file too because admin would not be able
> to reconfigure them.
> Does there is a nice solution (with out of custom code)?

You can use the VirtualWebappLoader, at least if Log4J in your webapps
is configured as usual using the class loader search. If it is
configured programmatically, then there is little you can do.

The VirtualWebappLoader allows to extend the search path for the class
loader of a web application by external directories and jars. So you can
e.g. add ${catalina.base}/ENGINE_NAME/HOST_NAME/CONTEXT_NAME/ the the
path for the context named CONTEXT_NAME.

The VirtualWebappLoader exists since quite some time in TC 6, but only
in TC 7 it gained non-experimental status. Nevertheless it does work in
TC 6 too. The configuration is done in a Loader element nested in the
Context element in the context deployment descriptor (aka context.xml or

For TC 6 the docs are somewhat hidden:

for TC 7 it is a first class citizen documented at

Important note: old versions of the VirtualWebappLoader appended the
additional search path components, so anything found inside the webapp
won. Of course here you want to overwrite something in the war, so you
want the path components to get prepended. The attribute
searchVirtualFirst="true" configures that. This is only available in TC
6.0.33 (and TC 7 since 7.0.0).


<?xml version="1.0" encoding="UTF-8"?>
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"

There is also another option: if you only want to make the path to the
log files configurable and you can agree on a solution with the webapp
developers, you can convince them to use a system property for the log
path, that you can set during TC startup. Since system properties are
global, you would need a different system property for each webapp if
you want to configure different directories.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message