tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Jung <rainer.j...@kippdata.de>
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/log4j.properties
> 
> 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
myapp.xml).

For TC 6 the docs are somewhat hidden:

http://tomcat.apache.org/tomcat-6.0-doc/api/index.html

for TC 7 it is a first class citizen documented at

http://tomcat.apache.org/tomcat-7.0-doc/config/loader.html#VirtualWebappLoader_Implementation

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).

Example:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
        searchVirtualFirst="true"
        virtualClasspath="${catalina.base}/conf/myapp"/>
</Context>

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.

Regards,

Rainer

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


Mime
View raw message