• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

System.out.println to a System file

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?

Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Saloon Keeper
Posts: 23272
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic