The Artima Developer Community
Sponsored Link

Java Answers Forum
Writing a Log File

3 replies on 1 page. Most recent reply: Aug 2, 2003 8:43 AM by Henry

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Henry

Posts: 7
Nickname: daviddavis
Registered: Aug, 2002

Writing a Log File Posted: Jul 27, 2003 8:24 AM
Reply to this message Reply
Advertisement
Hi,
I would like to write a app. that when oppen:
- log details such:
* Date,
* Time,
* Events such Errors...
Each time the program run it should create a new log file, but the previous one should remain in....
After I should be able to read the files with a Text editor (xx.text).

Many thanks for your help
Best wishes for your future.
DD


FredrikN

Posts: 22
Nickname: fredrikn
Registered: Jul, 2003

Re: Writing a Log File Posted: Jul 27, 2003 10:26 AM
Reply to this message Reply
Hi.
Try the following code, it will catch any error and then write it to a textfile.


try
{
//lots of code where something can go wrong
}
catch(Exception e)
{

BufferedWriter bw = new BufferedWriter(new FileWriter(file));
PrintWriter outFile = new PrintWriter(bw,true);
outFile.print(e);

//then also write the date and time, I'm sure
//you can find it yourself how to fix the rest :-)
outFile.print(date and time variable);

outFile.close();

}

Greg Lehane

Posts: 33
Nickname: glehane
Registered: Jun, 2003

Re: Writing a Log File Posted: Jul 27, 2003 4:46 PM
Reply to this message Reply
To do logging properly, take a look at Apache's log4j.

http://jakarta.apache.org/log4j/docs/index.html

=- Greg

Henry

Posts: 7
Nickname: daviddavis
Registered: Aug, 2002

Re: Writing a Log File Posted: Aug 2, 2003 8:43 AM
Reply to this message Reply
02 August 2003.
Many Thanks for your help.

Flat View: This topic has 3 replies on 1 page
Topic: Dynamic class loading Previous Topic   Next Topic Topic: read and write a text file using a textarea field in an applet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use