This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Help needed on File logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Help needed on File logging" Watch "Help needed on File logging" New topic
Author

Help needed on File logging

Stan Griffith
Greenhorn

Joined: Jun 04, 2005
Posts: 11
Hi All,

I have tried to write a common logging class that writes to a file.



I call the static methods of this class to get logger objects and whenever I need to write to a file. Currently, when I execute this, several log files get generated as well as '.lck' files in the current working dir. I am not sure why I am getting this behaviour (more than one log file and .lck file).

Any help is appreciated.

thanks

Stan
Yevgeniy Treyvus
Ranch Hand

Joined: Mar 09, 2005
Posts: 48
I think there are a couple of problems here. Each time you call your static methods that in turn creates a brand new instance of FileHandler class.

Instead you should create only one instance of the FileHandler class for each log file and work with that.

As a side note, both of you static methods (getClientLogger and getServerLogger) are nearly identical. Sun may take points off for that since this is generally a bad programming practice.

Instead try creating only one method (getLogger) and make it take some kind of parameter that will differentiate between the different logging modes (client & server). Doing so will half the size of you FileLogger class.


SCJP, SCJD
Stan Griffith
Greenhorn

Joined: Jun 04, 2005
Posts: 11
Thanks Yevgeniy. It worked for me. Sorry for the delaye in responding.

Stan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needed on File logging