• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

change standard output to a file

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly do you need to do???
 
Yan Bai
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stan,
the 2nd option works great.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic