aspose file tools*
The moose likes Beginning Java and the fly likes Writing into log file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Writing into log file" Watch "Writing into log file" New topic
Author

Writing into log file

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
I have finished developing a swing application and I would like to change all my System.out.println statements into log. I would like to write these lines into a log file for that application.
I am planning to concatenate all these strings into one string and finally opening a log file to write everything in one step before the program exit. B'cos I feel it would be cumbersome to open many times to write the System.out into log file (With as many as try catch.. as many as System.out statements). Any other nicer way to do this?
[ April 28, 2008: Message edited by: Gopu Akraju ]
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Hi
after googling I came to know about the class Logger. I treid a small example from the web as below.



The output looks like below:


Is there any better of doing this? Thanks.
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
logger works fine. How do I limit the size of the log file. After the file size has reached by 51MB, I want to flush the contents and starts writing again in the same file. Thanks in advance.
Laxman Guru
Greenhorn

Joined: Feb 26, 2008
Posts: 17
Refer Here


Laxman
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Thanks and I got it.



Even though I did go through api, I have a doubt about the third parameter (i.e count=1)DOes it mean, that once the log file size reaches 1MB, it flushes teh contents in MyLogFile.log and starts writing in the same file. Please clarify.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Try experimenting with different values and see what happens. You'll learn a lot more that way than just being told the answer.


Joanne
Laxman Guru
Greenhorn

Joined: Feb 26, 2008
Posts: 17
Even though I did go through api, I have a doubt about the third parameter (i.e count=1)DOes it mean, that once the log file size reaches 1MB, it flushes teh contents in MyLogFile.log and starts writing in the same file. Please clarify.


This is what you have asked above...Isn't?

This happens because you are limiting the size of the file to 1MB...Count is to rotate set of files...Set count as 2 and see what happens...
James Jiang
Greenhorn

Joined: Dec 13, 2007
Posts: 24
I think the third parameter is useful when you need to write the information into several log files,notice that the first parameter is a pattern of string,you can specify many log files like 1.log,2.log,3.log and so on.
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Thanks I got it.
 
Consider Paul's rocket mass heater.
 
subject: Writing into log file