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 04:49:55 UTC

swallowOutput="true" not working. Why?

Hi,

I just switched from Tomcat 5.5 to Tomcat 6 on an Ubuntu server.  I'm
trying to use log4j with this configuration:

log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.target=System.out
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

This was not working, so I searched documentation and learned about:

<Context swallowOutput="true"> ... </Context>

However, this swallowOutput doesn't seem to work.  I tried putting
this in several places:

1) in the sever-wide context.xml, which already exists and has a
<Context ...> element.  (On my system, this fil is in /etc/tomcat6).

2) There was no host-specific one, so I added the file
/etc/tomcat6/Catalina/localhost/context.xml with the contents:
<Context swallowOutput="true"/>

Note that ${CATALINA_HOME}/conf is a symlink to /etc/tomcat6, so when
the documentation refers to the locations for these files, I am pretty
sure I know which ones they're talking about.

3) Just to exhaust all possibilities, in my webapp's META-INF, I
created a context.xml file with the same contents.

None of these three things had any effect.  I tried it both with log4j
and, to rule out that log4j was the problem, tried some
System.out.println and System.err.println here and there.  Near as I
can this output goes nowhere.

I would REALLY like my log4j output to go to localhost_<datetime>.log.
 Otherwise, I think I have to do some screwing around with the
security manager in order to use something like the
RollingFileAppender.

I tried to follow http://tomcat.apache.org/tomcat-6.0-doc/logging.html
as best I could, including using tomcat-juli.jar from output/extras as
well as adding in tomcat-juli-adapters.jar.  I'm not sure if that
really applies, but was wondering ....

BTW the logger itself more-or-less seems to work.  I determined this
by doing something "wrong" just as a test: I called log4j's
BasicConfigurator.configure() to see what it would do.  I got log4j
logging output, but I would get duplicate log entries the more times I
reloaded my app.  I quickly figured out that I need to get the logger
as a static resource in whatever class wanted to log, e.g.

    private static Logger logger = Logger.getLogger(servletEventListener.class);


Thanks,

--Chris

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


Re: swallowOutput="true" not working. Why?

Posted by Daniele Development-ML <da...@googlemail.com>.
Hi Chris,
I'm coming across the same identical problem - your final message says you
have solved it. Could you post the detailed steps required to solve it? It
might beneficial to all of us.

Thanks,

Dan

On Mon, Jun 15, 2009 at 4:17 AM, Christopher Piggott <cp...@gmail.com>wrote:

> Konstantin,
>
> Thanks for sharing your experience.  It was helpful.
>
> I still have swallowOutput enabled but, with help from folks on this
> list, I kind of came to the same conclusion as you.  I also realized
> that I was making a mistake by trying to have my webapp use the shared
> copy of log4j rather than just including its own log4j in the .war.
> The reason had to do with the classloader, and which log4j.properties
> gets loaded for my webapp versus for catalina itself.  By sending
> another log4j with the webapp and following advice to go back to
> RollingFileAppender, I now have things working pretty sensibly.
>
> About the only real challenge now is dealing with things not yet smart
> enough to use log4j.  One of those things is jamod (a Modbus protocol
> implementation in Java) -- and it's enough of a problem that I'm
> rewriting its logging :)
>
> --Chris
>
>
> On Fri, Jun 12, 2009 at 1:54 PM, Konstantin
> Kolinko<kn...@gmail.com> wrote:
> > 2009/6/9 Christopher Piggott <cp...@gmail.com>:
> >> (...)
> >> This was not working, so I searched documentation and learned about:
> >>
> >> <Context swallowOutput="true"> ... </Context>
> >>
> >> However, this swallowOutput doesn't seem to work.  I tried putting
> >> this in several places:
> >> (...)
> >>
> >
> > If you are still puzzled with swallowOutput mistery, here is my
> experience.
> >
> > I tried a similar thing once, not with log4j, but with JULI in TC 5.5,
> > and also found
> > that swallowOutput does not work with logging frameworks.
> >
> > The reason, as I see it, is the following:
> > 1. to implement this functionality, Tomcat creates a custom
> > PrintStream (SystemLogHandler) and replaces the default System.out and
> > System.err
> >
> > 2. logging classes start up and are initialized before the above said
> happens,
> > and at their initialization time they get reference to the original
> System.out
> > and System.err PrintStreams, bypassing this replacement trick.
> >
> >
> > After some thought my conclusion was that there is too much of a trick
> > involved in that swallowOutput thing and I would better seek for
> > a solution inside the logging framework itself.
> >
> > Though I do not have a clear recipe yet. I was not very interested.
> >
> >
> > Best regards,
> > Konstantin Kolinko
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: swallowOutput="true" not working. Why?

Posted by Christopher Piggott <cp...@gmail.com>.
Konstantin,

Thanks for sharing your experience.  It was helpful.

I still have swallowOutput enabled but, with help from folks on this
list, I kind of came to the same conclusion as you.  I also realized
that I was making a mistake by trying to have my webapp use the shared
copy of log4j rather than just including its own log4j in the .war.
The reason had to do with the classloader, and which log4j.properties
gets loaded for my webapp versus for catalina itself.  By sending
another log4j with the webapp and following advice to go back to
RollingFileAppender, I now have things working pretty sensibly.

About the only real challenge now is dealing with things not yet smart
enough to use log4j.  One of those things is jamod (a Modbus protocol
implementation in Java) -- and it's enough of a problem that I'm
rewriting its logging :)

--Chris


On Fri, Jun 12, 2009 at 1:54 PM, Konstantin
Kolinko<kn...@gmail.com> wrote:
> 2009/6/9 Christopher Piggott <cp...@gmail.com>:
>> (...)
>> This was not working, so I searched documentation and learned about:
>>
>> <Context swallowOutput="true"> ... </Context>
>>
>> However, this swallowOutput doesn't seem to work.  I tried putting
>> this in several places:
>> (...)
>>
>
> If you are still puzzled with swallowOutput mistery, here is my experience.
>
> I tried a similar thing once, not with log4j, but with JULI in TC 5.5,
> and also found
> that swallowOutput does not work with logging frameworks.
>
> The reason, as I see it, is the following:
> 1. to implement this functionality, Tomcat creates a custom
> PrintStream (SystemLogHandler) and replaces the default System.out and
> System.err
>
> 2. logging classes start up and are initialized before the above said happens,
> and at their initialization time they get reference to the original System.out
> and System.err PrintStreams, bypassing this replacement trick.
>
>
> After some thought my conclusion was that there is too much of a trick
> involved in that swallowOutput thing and I would better seek for
> a solution inside the logging framework itself.
>
> Though I do not have a clear recipe yet. I was not very interested.
>
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


Re: swallowOutput="true" not working. Why?

Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/6/9 Christopher Piggott <cp...@gmail.com>:
> (...)
> This was not working, so I searched documentation and learned about:
>
> <Context swallowOutput="true"> ... </Context>
>
> However, this swallowOutput doesn't seem to work.  I tried putting
> this in several places:
> (...)
>

If you are still puzzled with swallowOutput mistery, here is my experience.

I tried a similar thing once, not with log4j, but with JULI in TC 5.5,
and also found
that swallowOutput does not work with logging frameworks.

The reason, as I see it, is the following:
1. to implement this functionality, Tomcat creates a custom
PrintStream (SystemLogHandler) and replaces the default System.out and
System.err

2. logging classes start up and are initialized before the above said happens,
and at their initialization time they get reference to the original System.out
and System.err PrintStreams, bypassing this replacement trick.


After some thought my conclusion was that there is too much of a trick
involved in that swallowOutput thing and I would better seek for
a solution inside the logging framework itself.

Though I do not have a clear recipe yet. I was not very interested.


Best regards,
Konstantin Kolinko

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


RE: swallowOutput="true" not working. Why?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: swallowOutput="true" not working. Why?
> 
> > 2) There was no host-specific one, so I added the file
> > /etc/tomcat6/Catalina/localhost/context.xml with the contents:
> > <Context swallowOutput="true"/>
> 
> This file will control the settings for a webapp called "context",
> which is probably not what you meant.

What the OP should have used is /etc/tomcat6/Catalina/localhost/context.xml.default, assuming /etc/tomcat6 actually has some meaning to this installation.  However, if the OP wants the swallowOutput setting to apply globally, /etc/tomcat6/context.xml would still be the preferred location.

I'd still advise installing a standard Tomcat from tomcat.apache.org just to eliminate the confusion that currently exists about where things are really located.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


Re: swallowOutput="true" not working. Why?

Posted by Christopher Piggott <cp...@gmail.com>.
Y

On Tue, Jun 9, 2009 at 3:45 PM, Christopher
Schultz<ch...@christopherschultz.net> wrote:
>> log4j.appender.R=org.apache.log4j.ConsoleAppender
>> log4j.appender.R.target=System.out
>> log4j.appender.R.layout=org.apache.log4j.PatternLayout
>> log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
>
> I've never used the "target" property... is this actually a thing?
> ConsoleAppender should already send messages to stdout.

Yeah, ConsoleAppender understands it ... but it's probably redundant
as System.out must be the default.

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


Re: swallowOutput="true" not working. Why?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris,

On 6/8/2009 10:49 PM, Christopher Piggott wrote:
> I just switched from Tomcat 5.5 to Tomcat 6 on an Ubuntu server.

Are you using the Ubuntu-managed version of Tomcat, or are you using one
that you installed from an official package from apache.org?

> I'm trying to use log4j with this configuration:

[Do you have Tomcat configured to use log4j in the first place?]

> log4j.appender.R=org.apache.log4j.ConsoleAppender
> log4j.appender.R.target=System.out
> log4j.appender.R.layout=org.apache.log4j.PatternLayout
> log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

I've never used the "target" property... is this actually a thing?
ConsoleAppender should already send messages to stdout.

> This was not working, so I searched documentation and learned about:
> 
> <Context swallowOutput="true"> ... </Context>

This setting will capture information sent to stdout by a particular
application and instead send it to the application log (which,
presumably will be sent to a file). If you just want to send your log4j
logs to a file, why not use log4j's /file/ logging capabilities instead
of piping everything around?

> However, this swallowOutput doesn't seem to work.  I tried putting
> this in several places:
> 
> 1) in the sever-wide context.xml, which already exists and has a
> <Context ...> element.  (On my system, this file is in /etc/tomcat6).

This is probably not a good place to put this setting: it will affect
/all/ webapps deployed into Tomcat. If you're using a package-managed
version of Tomcat (from Ubuntu) then this file is probably relevant. If
you installed your own from an official package, this file is probably
just garbage left behind from another installation of Tomcat.

> 2) There was no host-specific one, so I added the file
> /etc/tomcat6/Catalina/localhost/context.xml with the contents:
> <Context swallowOutput="true"/>

This file will control the settings for a webapp called "context", which
is probably not what you meant. If you want to define the configuration
for a webapp called "foo" then your file needs to be called "foo.xml"
(but still contain the same stuff you have above).

The best place to put your context.xml file is in META-INF/context.xml
within your webapp's WAR file (or exploded WAR file where you deploy
your app). Then you don't have to worry about where that config file
goes on the disk.

> 3) Just to exhaust all possibilities, in my webapp's META-INF, I
> created a context.xml file with the same contents.
> 
> None of these three things had any effect.

It's possible that all configs are fighting each other. Roll-back
everything and only do #3 above, then see how it goes.

> I tried it both with log4j
> and, to rule out that log4j was the problem, tried some
> System.out.println and System.err.println here and there.  Near as I
> can this output goes nowhere.

It would be good to get this working without log4j in the mix... your
System.out tests should be sufficient to prove that swallowOutput /is/
working.

> I would REALLY like my log4j output to go to localhost_<datetime>.log.
> Otherwise, I think I have to do some screwing around with the
> security manager in order to use something like the
> RollingFileAppender.

Aah... now it makes sense that you are using log4j + ConsoleAppender +
awallowOutput="true". Okay, I think this approach makes sense, but
something is obviously misconfigured somewhere.

> I tried to follow http://tomcat.apache.org/tomcat-6.0-doc/logging.html
> as best I could, including using tomcat-juli.jar from output/extras as
> well as adding in tomcat-juli-adapters.jar.  I'm not sure if that
> really applies, but was wondering ....

I don't think you need to do all of this... the out-of-the box logging
mechanism should work with swallowOutput="true". It's possible that the
Ubuntu packagers have done something that is making this difficult. Have
you checked your logging.properties file (somewhere in the Tomcat
install or /etc/tomcat5 or something like that) to see that it is sane?

You might want to cross-post to an Ubuntu forum to ask over there if
there's something Ubuntu-specific that might be causing a problem.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkouu9cACgkQ9CaO5/Lv0PDCBgCgkfhEhZxKOAWtjot6e0kDt1uP
TxMAnir+5Wf31VkfayQRu8PG8Uwkw2iX
=+vFJ
-----END PGP SIGNATURE-----

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