tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Single war file - multiple hosts - can't get log4j to log to different files
Date Wed, 23 Nov 2011 16:12:03 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris,

On 11/23/11 8:06 AM, chris derham wrote:
>>> We thought this would allow us to monitor all contexts with a 
>>> single probe install, but it only seems to show a single
>>> localhost context. I assume that the hosts are separated, and
>>> that the context="priviliged" setting can allow a web app to
>>> access other webapps in the same context, but not across
>>> hosts.
>> 
>> So... what setting is that?
>> 
> I meant the crossContext="true" setting. I have searched around,
> and can see that both tomcat's manager and probe are not able to
> monitor virtual hosts other than the one that they reside in. So I
> will just have to deploy manager and/or probe for each virtual
> host. I just wanted to see everything in a single place - from what
> I have read this can't be done

If you are lazy/memory conscious/can tolerate the setup, you could put
all webapps under a single virtual host (the default, most likely)
with aliases (if you even require them) and that would solve the
management problem.

>> 1. Move your .war files from out of the webapps directory (and
>> subdirs) 2. Update the paths in ROOT.xml and probe.xml to point
>> to the new location 3. Remove the "local" and "demos"
>> directories
>> 
> Thanks for the pointer. What I ended up doing was moving all wars
> to <CATALINA_BASE>/notWebapps. Then I unpacked them, and set the
> relevant context.xml's docbase to point to the exploded directory.
> Seems to work well now

Seems like a reasonable course of action. "notWebapps". I like that. :)

>>> The only idea I have left if nobody can see an obvious flaw in
>>> our logic is to write some custom code to initialise log4j. We
>>> would just need to pick up the context, or a jndi variable and
>>> then prefix the log file name with this. Guess it can't be that
>>> hard - just figured that somebody would have hit this before.
>> 
>> I think that's your best bet.
>> 
> Yes it was surprisingly easy. We created a subclass of springs 
> Log4jConfigListener, and then prefix the file parameter of any
> file appenders. We set the web.xml value to blank, which is
> ignored, and then when required we can override it in context.xml.
> Thanks for the pointer

You might want to put a comment in the web.xml where you have no value
explaining where the value is *really* located. You'll save some
sysasmin several hours of screaming in the future.

>> I'm not sure that using JMX is going to make your life any
>> easier.
> 
> I thought that via some internal to tomcat mechanism, I would be
> able to detect which context I was in, and thus be able to use that
> to drive the prefix for the log file, rather than having to have a
> specific web.xml setting that each context overrides.

You should be able to detect the context name during startup.
Actually, you can get the path from ServletContext.getContextPath. So,
if you have a ServletContextListener, you can do this:

event.getServletContext().getContextPath()

Of course, that gets you a string that you might need to massage (like
changing "" into "ROOT", removing slashes, etc.).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7NG1MACgkQ9CaO5/Lv0PCLdwCfQMZWqd0wDtwTXxiZgYyqtPTE
lowAn1tZMiEh1Qb4/NRpMeqKwXK18Glo
=wsFf
-----END PGP SIGNATURE-----

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


Mime
View raw message