• Post Reply Bookmark Topic Watch Topic
  • New Topic

change standard output to a file  RSS feed

 
Yan Bai
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember there's a way for System.out output to a file, so it can be saved easily. does anyone know how?

THanks.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you start Java from the command line you can redirect the output:

Once your code is running you can change where stdout goes

Does one of those do what you need?
 
Yan Bai
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stan.
1st one cannot be used coz it's a web application.
I am curious about the 2nd option. how can it be used in a web environment?
or is there a way to change the default output device from screen to something else?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you need to do???
 
Yan Bai
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 'System.out' lines in jsp/servlet pages, for basic debug purpose. Since the default system.out and system.err devices are the screen, the output information I specified are all mixed with Tomcat's embedded msg.

I want to seperate the information, e.g. let Tomcat intact, but output my system.out to somewhere else, such as a plain text file.

Instead of writing a redirect program by my own, I remember there's a way to change teh default output device for JVM, but how? your inputs are very appreicated...
 
Yan Bai
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stan,
the 2nd option works great.
 
Ramen Chatterjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Just to clariy..

.. 1>stdout.txt 2>err.txt

First part means redirect std out to file
Second part means redirect std error to file

BTW, if these are servlets why not use the log() method?

Regards

Ramen
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes servlet-containers (like tomcat) use themselves logging frameworks. so go use them, too.

you really should avoid use System.out. for logging messages, soon or after it gets a pain: it's difficult to redirect it, no enforement of an output pattern, no simple switching off etc.

try out log4j
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!