Jan 30, 2012 8:03 pm
FrameHi:
We have an existing Java program, which prints out a lot of message
using System.out.println() method to the console. There are about 500
those calls in the code. We hope to add one more feature: besides
print out to the console as it is doing now, we also want to store
those messages in a text file. So the message will be in two places:
one place -- the console -- is shown the message progressively as the
program is running; another place -- a text file -- is created at the
end of the program.
Since there are about 500 calls in the code, we don't want to add a
duplicated printing method at every printing place. I am thinking to
let the program run as usal, printing out all the messages to the
console, then before the program ends, having a method reading in
every line on the console, which was printed out previously. I just
don't know how to achieve that.
Thank you very much.
Jan 30, 2012 8:14 pm
Stefan Ramframe <xsli2@yahoo.com> writes:
>Since there are about 500 calls in the code, we don't want to add a
>duplicated printing method at every printing place. I am thinking to
>duplicated printing method at every printing place. I am thinking to
http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#setOut(java.io.PrintStream)
Jan 30, 2012 8:18 pm
Glen herrmannsfeldtframe <xsli2@yahoo.com> wrote:
> We have an existing Java program, which prints out a lot of message
> using System.out.println() method to the console. There are about 500
> those calls in the code. We hope to add one more feature: besides
> print out to the console as it is doing now, we also want to store
> those messages in a text file. So the message will be in two places:
> one place -- the console -- is shown the message progressively as the
> program is running; another place -- a text file -- is created at the
> end of the program.
> using System.out.println() method to the console. There are about 500
> those calls in the code. We hope to add one more feature: besides
> print out to the console as it is doing now, we also want to store
> those messages in a text file. So the message will be in two places:
> one place -- the console -- is shown the message progressively as the
> program is running; another place -- a text file -- is created at the
> end of the program.
The old-fashioned way on unix is the tee command, which you can pipe
into, and will write to a file and stdout.
It should be easy to port to other systems with pipe, such as Windows.
-- glen
Jan 30, 2012 10:18 pm
Daniel PittsOn 1/30/12 12:03 PM, frame wrote:
> Hi:
>
> We have an existing Java program, which prints out a lot of message
> using System.out.println() method to the console. There are about 500
> those calls in the code. We hope to add one more feature: besides
> print out to the console as it is doing now, we also want to store
> those messages in a text file. So the message will be in two places:
> one place -- the console -- is shown the message progressively as the
> program is running; another place -- a text file -- is created at the
> end of the program.
>
> Since there are about 500 calls in the code, we don't want to add a
> duplicated printing method at every printing place. I am thinking to
> let the program run as usal, printing out all the messages to the
> console, then before the program ends, having a method reading in
> every line on the console, which was printed out previously. I just
> don't know how to achieve that.
>
> Thank you very much.
>
Perhaps System.out isn't the way to go. You might want to look into >
> We have an existing Java program, which prints out a lot of message
> using System.out.println() method to the console. There are about 500
> those calls in the code. We hope to add one more feature: besides
> print out to the console as it is doing now, we also want to store
> those messages in a text file. So the message will be in two places:
> one place -- the console -- is shown the message progressively as the
> program is running; another place -- a text file -- is created at the
> end of the program.
>
> Since there are about 500 calls in the code, we don't want to add a
> duplicated printing method at every printing place. I am thinking to
> let the program run as usal, printing out all the messages to the
> console, then before the program ends, having a method reading in
> every line on the console, which was printed out previously. I just
> don't know how to achieve that.
>
> Thank you very much.
>
logging frameworks, such as commons logging or log4j. They provide that
kind of flexibility and more.
Previous Thread: Resource confusion
Next Thread: Java DB rotation
Related Forum Topics
- Inserting Multiple Lines from Console
- Read DEL and BACK key from stdin
- Back to .Net? lesser of two evils?
- Ant task to compute lines of code
- Input from Console
- How to send console progress information to gui
- I write a console java edition of top
- How to create a batch file for Java Console Application?
- How can I read from the entire standard input at once?
- Read java Annotation field values from class