Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to read back the lines printed out to the console?

Reply
Thread Tools

how to read back the lines printed out to the console?

 
 
Lew
Guest
Posts: n/a
 
      01-31-2012
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/wikipedi.../c/cf/Friz.jpg
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      02-01-2012
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

 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      02-01-2012
On 1/31/2012 2:11 PM, Lew wrote:
> On 01/31/2012 10:09 AM, frame wrote:
>> Wow. Thank you so much. I greatly appreciate your effort for putting
>> up such complete and nicely formatted code, including testing code.
>> Thank you very very much.
>>
>> Like Patricia said, I am almost there. Based on your code, my class
>> ends up to be:
>>
>> class TeeOutputStream extends OutputStream
>> {

> ...
>
>> Since now, all System.out.println(..) message is shown on the console
>> progressively when the program running and be saved into a file at the
>> end by writing out our logger object to a xml file.
>>
>> Thank you again for all the help.

>
> This is still far harder, more fragile and less flexible that biting the
> bullet and *using a logging framework*.
>
> In your career you will have to learn when to do the right thing. Doing
> the wrong thing, although you believe it now to be more expedient, will
> inevitably bite you in the ass. Hopefully at that time you'll say to
> yourself, "Well, Lew warned me this was going to happen. I should have
> listened back then when it was only a simple matter of substituting text
> in 500 locations instead of having to maintain this kludgey, buggy,
> large subsystem."


I don't think setting out to an instance of a relative simple
class qualifies as "large subsystem".

If they have time, then converting to a logging framework is the
right solution.

If they do not have time, then setting out now and put switching
to a logging framework on the TODO list is the right solution.

We all know that this type of item can be on the TODO list
for years without being implemented, but sometimes the time
is just not there to do the right thing.

Arne

 
Reply With Quote
 
frame
Guest
Posts: n/a
 
      02-01-2012
L-E-W:

I bet you have smelled out who I am, even though I have switched my
user name. Let me get things straight here:

1)first, as far as I understand, this Java news group is a public news
group, not *your* private news group. I have the right to join and
post.

2)second, this is a *free* public list, since you have emphasized
before that I have got free answers. If you think I should be charged
for what I am getting here, change the rule of this news group and
make it clear upfront.

3)third, I am not demanding anybody -- including you definitely-- to
answer my questions: if somebody wants to answer, he is more than
welcome to; if he does not want to, that is totally fine.

What I have been done on this Java news group and other news groups
completely follow the rules.

4)This is for you only, please *do not* answer my post. I don't
appreciate any of your posts. To be honest, I have ignored almost all
of them. To me, you are a very old hand of Java, with very little of
understanding of it. Spend your "Java knowledge" somewhere else, ok?

If you have a job with health insurance, I advise you seek mental
health treatment. Killing your time on the internet does not cure your
problem. It makes it worse.
 
Reply With Quote
 
Ian Shef
Guest
Posts: n/a
 
      02-01-2012
frame <> wrote in news:5b9a123d-c912-435d-b13d-4abd7e171053
@o12g2000vbd.googlegroups.com:

> L-E-W:
>
> I bet you have smelled out who I am, even though I have switched my
> user name. Let me get things straight here:
>
> 1)first, as far as I understand, this Java news group is a public news
> group, not *your* private news group. I have the right to join and
> post.


.... and so does Lew !
>
> 2)second, this is a *free* public list, since you have emphasized
> before that I have got free answers. If you think I should be charged
> for what I am getting here, change the rule of this news group and
> make it clear upfront.


???
>
> 3)third, I am not demanding anybody -- including you definitely-- to
> answer my questions: if somebody wants to answer, he is more than
> welcome to; if he does not want to, that is totally fine.
>
> What I have been done on this Java news group and other news groups
> completely follow the rules.
>
> 4)This is for you only, please *do not* answer my post. I don't
> appreciate any of your posts. To be honest, I have ignored almost all
> of them. To me, you are a very old hand of Java, with very little of
> understanding of it. Spend your "Java knowledge" somewhere else, ok?


Lew is free to post as he sees fit. He has tremendous knowledge and
experience with Java. By ignoring his attempts to help you, you are
ignoring a powerful resource. Too bad.


>
> If you have a job with health insurance, I advise you seek mental
> health treatment. Killing your time on the internet does not cure your
> problem. It makes it worse.
>


Personal attacks are not helpful. This one is particularly unfair and out
of line.

You and Lew are both free to post. It would be helpful if the postings are
kept friendly, or at least professional. A good newsreader will allow you
to ignore Lew's postings, but you do so at your own "Java peril".



 
Reply With Quote
 
frame
Guest
Posts: n/a
 
      02-01-2012
On Feb 1, 2:15*pm, Ian Shef <inva...@avoiding.spam> wrote:

>
> Lew is free to post as he sees fit. *He has tremendous knowledge and
> experience with Java. *By ignoring his attempts to help you, you are
> ignoring a powerful resource. *Too bad.
>
>
>
> > If you have a job with health insurance, I advise you seek mental
> > health treatment. Killing your time on the internet does not cure your
> > problem. It makes it worse.

>
> Personal attacks are not helpful. *This one is particularly unfair and out
> of line.
>
> You and Lew are both free to post. *It would be helpful if the postingsare
> kept friendly, or at least professional. *A good newsreader will allow you
> to ignore Lew's postings, but you do so at your own "Java peril".


If the OP does not appreciate that person's posting and that person
just insist doing so, that must be some reason of "friendly", "at
least professional" or mental health problem.
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      02-01-2012
On Wed, 1 Feb 2012 12:59:51 -0800 (PST), frame <>
wrote:

[snip]

>If the OP does not appreciate that person's posting and that person
>just insist doing so, that must be some reason of "friendly", "at
>least professional" or mental health problem.


I find Lew to be rather brash, but your attacks are over the top.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      02-02-2012
On 2/1/2012 9:01 AM, frame wrote:
> L-E-W:
>
> I bet you have smelled out who I am, even though I have switched my
> user name.


I have not.

> Let me get things straight here:
>
> 1)first, as far as I understand, this Java news group is a public news
> group, not *your* private news group. I have the right to join and
> post.


True.

> 2)second, this is a *free* public list, since you have emphasized
> before that I have got free answers. If you think I should be charged
> for what I am getting here, change the rule of this news group and
> make it clear upfront.


True.

> 3)third, I am not demanding anybody -- including you definitely-- to
> answer my questions: if somebody wants to answer, he is more than
> welcome to; if he does not want to, that is totally fine.
>
> What I have been done on this Java news group and other news groups
> completely follow the rules.


True.

> 4)This is for you only, please *do not* answer my post. I don't
> appreciate any of your posts. To be honest, I have ignored almost all
> of them. To me, you are a very old hand of Java, with very little of
> understanding of it. Spend your "Java knowledge" somewhere else, ok?


Try google for killfile.

> If you have a job with health insurance, I advise you seek mental
> health treatment. Killing your time on the internet does not cure your
> problem. It makes it worse.


I think you should take your own advice.

Lew insisted that you should switch to a logging framework.

One can agree or disagree, but it is something that can
be argued.

Your post on the other hand is not good behavior.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines? PerlFAQ Server Perl Misc 0 01-14-2011 05:00 AM
How to filter out lines from a variable that has multi-lines? mike Perl Misc 3 10-02-2007 12:08 AM
LInes on printed photos nipper.dawg@gmail.com Digital Photography 1 12-19-2006 07:27 PM
Re: how to read 10 lines from a 200 lines file and write to a new file?? Joe Wright C Programming 0 07-27-2003 08:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57