Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing into log file

 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer Here
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try experimenting with different values and see what happens. You'll learn a lot more that way than just being told the answer.
 
Laxman Guru
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic