You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Piggott <cp...@gmail.com> on 2009/06/09 15:46:51 UTC
swallowOutput and service threads
Hi,
I'm running tomcat 6 and am having the problem that swallowOutput
doesn't work for my service threads (i.e. threads owned by the webapp,
created in ServletContextListener.contextInitialized() and managed
entirely by me).
I noticed that swallowOutput="true" doesn't seem to affect these child
threads. Is there something that I have to do when I initialize my
service thread to map its stdout/stderr to the rest of the webapp's,
so that swallowOutput works on these children?
--Chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: swallowOutput and service threads
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chris,
On 6/9/2009 10:22 PM, Christopher Piggott wrote:
> I will definitely try that. I also will consider using log4j's
> rotating file appender instead of the ConsoleAppender. The reason I
> didn't do this in the first place is permissions: I don't normally
> have webapps that are able to write their own files. I will have to
> think about this a little.
Yeah, log4j is /much/ more robust than what Tomcat provides out of the
box (through "JULI"). Note that you /can/ configure Tomcat to use log4j
as well, so you can kind of do both :)
I prefer log4j's rolling semantics, anyway (file is called foo.log until
it is rotated to foo-2009-06-10.log, rather than juli's behavior which
is to /always/ have the date in the file name ... that makes log
watching difficult).
There are also other options for log4j: your webapp doesn't necessarily
need to log to a file... you can log to syslog - even on another
machine: instant cluster log aggregation.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkowGD8ACgkQ9CaO5/Lv0PDnRACfU5SBCh4A14XimktKpdSGRZbX
KRgAoJrvyNIggep7CqyN4DJOyNdMt2cF
=LhbX
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: swallowOutput and service threads
Posted by Christopher Piggott <cp...@gmail.com>.
> (By the way, did you solve your other problem of not getting *any*
> stdout output swallowed when swallowOutput="true"?)
Yep. I put it in what is essentially $CATALINA_HOME/conf/context.xml
which means it's server-wide and not host-specific ... and as you
pointed out, is a setting for all webapps. For now this is what I
want ... at least until I can go through all my servlets and make sure
they log properly. I'm carrying a lot of little apps I wrote a long
time ago that don't use a Logger. I've come to see the value of doing
it with log4j but it'll take me a little while to get everything
inline.
> You may have to set the thread's context classloader like this:
>
> public void contextInitialized(...)
> {
> Thread t = new Thread();
>
> t.setContextClassLoader(Thread.currentThread()
> .getContextClassLoader());
> }
>
I will definitely try that. I also will consider using log4j's
rotating file appender instead of the ConsoleAppender. The reason I
didn't do this in the first place is permissions: I don't normally
have webapps that are able to write their own files. I will have to
think about this a little.
Thanks for all your help!
--Chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: swallowOutput and service threads
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chris,
On 6/9/2009 9:46 AM, Christopher Piggott wrote:
> I'm running tomcat 6 and am having the problem that swallowOutput
> doesn't work for my service threads (i.e. threads owned by the webapp,
> created in ServletContextListener.contextInitialized() and managed
> entirely by me).
(By the way, did you solve your other problem of not getting *any*
stdout output swallowed when swallowOutput="true"?)
> I noticed that swallowOutput="true" doesn't seem to affect these child
> threads. Is there something that I have to do when I initialize my
> service thread to map its stdout/stderr to the rest of the webapp's,
> so that swallowOutput works on these children?
You may have to set the thread's context classloader like this:
public void contextInitialized(...)
{
Thread t = new Thread();
t.setContextClassLoader(Thread.currentThread()
.getContextClassLoader());
}
The javadoc for setContextClassLoader /plus/ a recent post on this list
indicate that you might have to specifically enable a permission for
this method in order to run successfully under a SecurityManager.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkouvMAACgkQ9CaO5/Lv0PA0wACfVBJ8lkdHF2xslIIJXLW4iby6
JLAAoLNjQ1pq1BrQGU2z2vYoQaUSRNwb
=TcFR
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org