Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11634 > unrolled thread
| Started by | frame <xsli2@yahoo.com> |
|---|---|
| First post | 2012-01-30 12:03 -0800 |
| Last post | 2012-01-31 11:17 -0800 |
| Articles | 9 on this page of 29 — 11 participants |
Back to article view | Back to comp.lang.java.programmer
how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-01-30 12:03 -0800
Re: how to read back the lines printed out to the console? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-01-30 20:18 +0000
Re: how to read back the lines printed out to the console? Roedy Green <see_website@mindprod.com.invalid> - 2012-01-30 20:42 -0800
Re: how to read back the lines printed out to the console? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-30 14:18 -0800
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 19:34 -0500
Re: how to read back the lines printed out to the console? Patricia Shanahan <pats@acm.org> - 2012-01-30 14:37 -0800
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 20:08 -0500
Re: how to read back the lines printed out to the console? Patricia Shanahan <pats@acm.org> - 2012-01-30 17:18 -0800
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 21:00 -0500
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 19:33 -0500
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 19:35 -0500
Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-01-31 10:09 -0800
Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-31 11:11 -0800
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-31 20:39 -0500
Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-02-01 06:01 -0800
Re: how to read back the lines printed out to the console? Ian Shef <invalid@avoiding.spam> - 2012-02-01 19:15 +0000
Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-02-01 12:59 -0800
Re: how to read back the lines printed out to the console? Gene Wirchenko <genew@ocis.net> - 2012-02-01 14:00 -0800
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-02-01 19:27 -0500
Re: how to read back the lines printed out to the console? frame <xsli2@yahoo.com> - 2012-01-30 18:49 -0800
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-30 21:56 -0500
Re: how to read back the lines printed out to the console? Patricia Shanahan <pats@acm.org> - 2012-01-30 19:06 -0800
Re: how to read back the lines printed out to the console? Roedy Green <see_website@mindprod.com.invalid> - 2012-01-30 20:46 -0800
Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-30 21:18 -0800
Re: how to read back the lines printed out to the console? Arne Vajhøj <arne@vajhoej.dk> - 2012-01-31 20:36 -0500
Re: how to read back the lines printed out to the console? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2012-01-31 10:18 +0200
Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-31 11:15 -0800
Re: how to read back the lines printed out to the console? bugbear <bugbear@trim_papermule.co.uk_trim> - 2012-01-31 09:50 +0000
Re: how to read back the lines printed out to the console? Lew <noone@lewscanon.com> - 2012-01-31 11:17 -0800
Page 2 of 2 — ← Prev page 1 [2]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-01-30 21:56 -0500 |
| Message-ID | <4f27584e$0$288$14726298@news.sunsite.dk> |
| In reply to | #11663 |
On 1/30/2012 9:49 PM, frame wrote:
> Thank you very much for all the replies. Probably I didn't explain my
> question clear. After reading all the replies, I am sorry I still
> didn't get the idea to proceed.
>
> My problem is such: our finished Java program has many printing
> statements, e.g.
>
> System.out.println("step A: everything is ok");
> ...
> System.out.println("step B: computation starts now");
> ...
>
> if(so)
> {
> System.out.println("warning: temperature is too hot");
> }
>
> There are about 500 of those. When we run the program, all these
> messages show up on the console -- that's good. But now, we also want
> to keep those messages in a file. I have two ideas, but none of them
> is acceptable:
>
> 1)at the beginning of the program, I added a little piece of code(re-
> direct the System output to a file), now all the existing 500
> System.out.println(..) prints to a file, not the console any more --
> this is not good, because the program runs up to 5 hours, we hope to
> see the message progressively on the console. With this approach, we
> have to wait till the program finished and open the text file to read.
> 2)another approach, use log4j to replace those 500 printing statements
> -- we are not ready for this approach right now, because there are 500
> of them -- in many classes. log4j has different levels(INFO, WARNING,
> ERROR etc). We need to analyze every printing case to decide its
> level. It is a too big approach for now.
>
> Ideally, I was wondering if this is possible: at the end of the
> program, when all those messages have been printed out to the console,
> I can added a small piece of code, which will read all the lines on
> the console back, then write them into a text file. I don't know if
> this makes sense.
So far you have not explained why the proposed solution of
System.setOut to a PrintStream that writes to both console and
file does not work.
Arne
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-01-30 19:06 -0800 |
| Message-ID | <aKudnXVEcI0Cx7rSnZ2dnUVZ_tKdnZ2d@earthlink.com> |
| In reply to | #11663 |
On 1/30/2012 6:49 PM, frame wrote:
> Thank you very much for all the replies. Probably I didn't explain my
> question clear. After reading all the replies, I am sorry I still
> didn't get the idea to proceed.
>
> My problem is such: our finished Java program has many printing
> statements, e.g.
>
> System.out.println("step A: everything is ok");
> ...
> System.out.println("step B: computation starts now");
> ...
>
> if(so)
> {
> System.out.println("warning: temperature is too hot");
> }
>
> There are about 500 of those. When we run the program, all these
> messages show up on the console -- that's good. But now, we also want
> to keep those messages in a file. I have two ideas, but none of them
> is acceptable:
>
> 1)at the beginning of the program, I added a little piece of code(re-
> direct the System output to a file), now all the existing 500
> System.out.println(..) prints to a file, not the console any more --
> this is not good, because the program runs up to 5 hours, we hope to
> see the message progressively on the console. With this approach, we
> have to wait till the program finished and open the text file to read.
You are almost there. Instead of using a PrintStream subclass that
writes only to the console, or one that writes only to a file, you need
one that writes to both.
Patricia
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-01-30 20:46 -0800 |
| Message-ID | <mbsei7hhfn78utkbgt30d9kdvomdrjdipt@4ax.com> |
| In reply to | #11663 |
On Mon, 30 Jan 2012 18:49:45 -0800 (PST), frame <xsli2@yahoo.com> wrote, quoted or indirectly quoted someone who said : >Ideally, I was wondering if this is possible: at the end of the >program, when all those messages have been printed out to the console, >I can added a small piece of code, which will read all the lines on >the console back, then write them into a text file. I don't know if >this makes sense. For one project, I wrote a console logger that used a GUI and a JTable. It let you scroll back and forth over the entire log while it was running. It also let me have a quite fancy log with colours, icons and items that faded over time. Another one had a "log" that was kept sorted with the most important things to notice at the top. -- Roedy Green Canadian Mind Products http://mindprod.com One of the most useful comments you can put in a program is "If you change this, remember to change ?XXX? too".
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-01-30 21:18 -0800 |
| Message-ID | <jg7tip$qrt$1@news.albasani.net> |
| In reply to | #11663 |
On 01/30/2012 06:49 PM, frame wrote:
> Thank you very much for all the replies. Probably I didn't explain my
> question clear. After reading all the replies, I am sorry I still
> didn't get the idea to proceed.
>
> My problem is such: our finished Java program has many printing
> statements, e.g.
>
> System.out.println("step A: everything is ok");
> ...
> System.out.println("step B: computation starts now");
> ...
>
> if(so)
> {
> System.out.println("warning: temperature is too hot");
> }
>
> There are about 500 of those. When we run the program, all these
> messages show up on the console -- that's good. But now, we also want
> to keep those messages in a file. I have two ideas, but none of them
> is acceptable:
>
> 1)at the beginning of the program, I added a little piece of code(re-
> direct the System output to a file), now all the existing 500
> System.out.println(..) prints to a file, not the console any more --
> this is not good, because the program runs up to 5 hours, we hope to
> see the message progressively on the console. With this approach, we
> have to wait till the program finished and open the text file to read.
> 2)another approach, use log4j to replace those 500 printing statements
> -- we are not ready for this approach right now, because there are 500
> of them -- in many classes. log4j has different levels(INFO, WARNING,
> ERROR etc). We need to analyze every printing case to decide its
> level. It is a too big approach for now.
>
> Ideally, I was wondering if this is possible: at the end of the
> program, when all those messages have been printed out to the console,
> I can added a small piece of code, which will read all the lines on
> the console back, then write them into a text file. I don't know if
> this makes sense.
People have already answered this question in detail, with code examples.
But what you really need to do is take the suggestion to use a logging
framework. Then you can change the configuration in a properties file with no
code changes. 500 instances isn't very many, especially with a global
's/System.out.println/logger.info/'. Any decent IDE will let you do that in a
single pop.
Do that. Really. It's the right thing to do.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-01-31 20:36 -0500 |
| Message-ID | <4f28971a$0$283$14726298@news.sunsite.dk> |
| In reply to | #11669 |
On 1/31/2012 12:18 AM, Lew wrote:
> On 01/30/2012 06:49 PM, frame wrote:
>> Thank you very much for all the replies. Probably I didn't explain my
>> question clear. After reading all the replies, I am sorry I still
>> didn't get the idea to proceed.
>>
>> My problem is such: our finished Java program has many printing
>> statements, e.g.
>>
>> System.out.println("step A: everything is ok");
>> ...
>> System.out.println("step B: computation starts now");
>> ...
>>
>> if(so)
>> {
>> System.out.println("warning: temperature is too hot");
>> }
>>
>> There are about 500 of those. When we run the program, all these
>> messages show up on the console -- that's good. But now, we also want
>> to keep those messages in a file. I have two ideas, but none of them
>> is acceptable:
>>
>> 1)at the beginning of the program, I added a little piece of code(re-
>> direct the System output to a file), now all the existing 500
>> System.out.println(..) prints to a file, not the console any more --
>> this is not good, because the program runs up to 5 hours, we hope to
>> see the message progressively on the console. With this approach, we
>> have to wait till the program finished and open the text file to read.
>> 2)another approach, use log4j to replace those 500 printing statements
>> -- we are not ready for this approach right now, because there are 500
>> of them -- in many classes. log4j has different levels(INFO, WARNING,
>> ERROR etc). We need to analyze every printing case to decide its
>> level. It is a too big approach for now.
>>
>> Ideally, I was wondering if this is possible: at the end of the
>> program, when all those messages have been printed out to the console,
>> I can added a small piece of code, which will read all the lines on
>> the console back, then write them into a text file. I don't know if
>> this makes sense.
>
> People have already answered this question in detail, with code examples.
>
> But what you really need to do is take the suggestion to use a logging
> framework. Then you can change the configuration in a properties file
> with no code changes. 500 instances isn't very many, especially with a
> global 's/System.out.println/logger.info/'. Any decent IDE will let you
> do that in a single pop.
Hmm.
PrintStream refs pointing to System.out, byte code only doing it ...
What IDE handle those?
Arne
[toc] | [prev] | [next] | [standalone]
| From | Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> |
|---|---|
| Date | 2012-01-31 10:18 +0200 |
| Message-ID | <m3r4yg70a8.fsf@despammed.com> |
| In reply to | #11663 |
frame <xsli2@yahoo.com> writes: > 1)at the beginning of the program, I added a little piece of code(re- > direct the System output to a file), now all the existing 500 > System.out.println(..) prints to a file, not the console any more -- > this is not good, because the program runs up to 5 hours, we hope to > see the message progressively on the console. With this approach, we > have to wait till the program finished and open the text file to read. Can't you use tail -f on another console (or equivalent for windows)? And of course, other people have suggested replacing System.out with a stream that prints to both console and a file. However, redirecting the output and reading the file simultaneously with tail might be possible without even recompiling the program. -- Jukka Lahtinen
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-01-31 11:15 -0800 |
| Message-ID | <jg9ek9$13c$3@news.albasani.net> |
| In reply to | #11673 |
On 01/31/2012 12:18 AM, Jukka Lahtinen wrote: > frame<xsli2@yahoo.com> writes: > >> 1)at the beginning of the program, I added a little piece of code(re- >> direct the System output to a file), now all the existing 500 >> System.out.println(..) prints to a file, not the console any more -- >> this is not good, because the program runs up to 5 hours, we hope to >> see the message progressively on the console. With this approach, we >> have to wait till the program finished and open the text file to read. > > Can't you use tail -f on another console (or equivalent for windows)? > > And of course, other people have suggested replacing System.out with a > stream that prints to both console and a file. > However, redirecting the output and reading the file simultaneously with > tail might be possible without even recompiling the program. Or he could use the actual 'tee' command as suggested upstream. Or he could do the right thing and drop the stupid 'System.out' logging and use a real logging framework. ONE COMES WITH JAVA for Pete's sake! -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | bugbear <bugbear@trim_papermule.co.uk_trim> |
|---|---|
| Date | 2012-01-31 09:50 +0000 |
| Message-ID | <TKWdnWA6rv3GJLrSnZ2dnUVZ8hidnZ2d@brightview.co.uk> |
| In reply to | #11663 |
frame wrote:
> Thank you very much for all the replies. Probably I didn't explain my
> question clear. After reading all the replies, I am sorry I still
> didn't get the idea to proceed.
>
> My problem is such: our finished Java program has many printing
> statements, e.g.
>
> System.out.println("step A: everything is ok");
> ...
> System.out.println("step B: computation starts now");
> ...
>
> if(so)
> {
> System.out.println("warning: temperature is too hot");
> }
>
> There are about 500 of those. When we run the program, all these
> messages show up on the console -- that's good. But now, we also want
> to keep those messages in a file. I have two ideas, but none of them
> is acceptable:
>
> 1)at the beginning of the program, I added a little piece of code(re-
> direct the System output to a file), now all the existing 500
> System.out.println(..) prints to a file, not the console any more --
> this is not good, because the program runs up to 5 hours, we hope to
> see the message progressively on the console. With this approach, we
> have to wait till the program finished and open the text file to read.
> 2)another approach, use log4j to replace those 500 printing statements
> -- we are not ready for this approach right now, because there are 500
> of them -- in many classes. log4j has different levels(INFO, WARNING,
> ERROR etc). We need to analyze every printing case to decide its
> level. It is a too big approach for now.
Since ALL your messages come out at one level at the moment,
you can assign an arbitrary level (say INFO) in Log4j, and have
the same level of control you currently have (none), and fulfil
your "file" requirment. Refining the Log4j levels can be deferred
indefinitely, according to business requirments.
BugBear
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-01-31 11:17 -0800 |
| Message-ID | <jg9enn$13c$4@news.albasani.net> |
| In reply to | #11674 |
On 01/31/2012 01:50 AM, bugbear wrote:
> frame wrote:
>> Thank you very much for all the replies. Probably I didn't explain my
>> question clear. After reading all the replies, I am sorry I still
>> didn't get the idea to proceed.
>>
>> My problem is such: our finished Java program has many printing
>> statements, e.g.
>>
>> System.out.println("step A: everything is ok");
>> ...
>> System.out.println("step B: computation starts now");
>> ...
>>
>> if(so)
>> {
>> System.out.println("warning: temperature is too hot");
>> }
>>
>> There are about 500 of those. When we run the program, all these
>> messages show up on the console -- that's good. But now, we also want
>> to keep those messages in a file. I have two ideas, but none of them
>> is acceptable:
>>
>> 1)at the beginning of the program, I added a little piece of code(re-
>> direct the System output to a file), now all the existing 500
>> System.out.println(..) prints to a file, not the console any more --
>> this is not good, because the program runs up to 5 hours, we hope to
>> see the message progressively on the console. With this approach, we
>> have to wait till the program finished and open the text file to read.
>> 2)another approach, use log4j to replace those 500 printing statements
>> -- we are not ready for this approach right now, because there are 500
>> of them -- in many classes. log4j has different levels(INFO, WARNING,
>> ERROR etc). We need to analyze every printing case to decide its
>> level. It is a too big approach for now.
>
> Since ALL your messages come out at one level at the moment,
> you can assign an arbitrary level (say INFO) in Log4j, and have
> the same level of control you currently have (none), and fulfil
> your "file" requirment. Refining the Log4j levels can be deferred
> indefinitely, according to business requirments.
That's right, "frame", and it's interesting that although every single one of
your objections to using a logger has been answered, and we've shown that the
effort to make the change is FAR less than what you're doing, you have not
acknowledged the answers, paid attention to advice far more expert than your
own, or done the right thing.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.java.programmer
csiph-web