Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.out.println to a System file

 
Venkat Srini
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Regards,
Venkat
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic