File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes System.out.println to a System file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "System.out.println to a System file" Watch "System.out.println to a System file" New topic

System.out.println to a System file

Venkat Srini

Joined: Jul 30, 2004
Posts: 3

I am using Apache Tomcat v 1.3.x. I would like to route all my System.out.println messages to a system file. How do I configure this? I don't want to make any changes to my JSP/Java files. Currently, the messages go to the console and I can't really track what's happening Can you please help me out?

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Tomcat 1.3 ? You sure about that number ?

As for system.out, this is a poor choice for doing debugging / logging.

System.out is *supposed* to go to the console. Were you expecting anything else? Log4j is highly recommended in these situations. You can configure individual packages and classes to produce output at separate levels. This is the way to go.

If you just don't want to change anything though... you'll have to use Tomcat's "swallowOutput" configuration. This will redirect System.out to the log file that is configured for your host. Though if you're truly using Tomcat 1.3, I wouldn't know how to do that for this version.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

Use of System.out and System.err for tracing and logging is a practice highly to be discouraged. Not all appservers send the System outputs to the same places - I've seen specifically differences between where stuff goes in Solaris Tomcat vs. Linux Tomcat. And some appservers may lose the output entirely or scramble System.out and System.err together.

Of course it usually works, and I do it for quick-and-dirty stuff, but I don't do it for production apps, and never for something I expect to be portable.

Tomcat has some very extensive logging abilities attached to its Valve components. I recommend you read up on them and see if you find something you like. If you don't like them, of course, you can write your own Valve to log the way you do like.

The actual application logging itself is supported as part of J2EE, JDK 1.4 and later, and various 3d-party add-ons such as log4j. You can start out simple by just using Servlet.log() and add more complex loggers as/if needed.

And, BTW, note that there's a version of Servlet.log that allows you to log Exceptions, so you can capture stack traces!

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: System.out.println to a System file
It's not a secret anymore!