3

I am using the java.util.logging API and atatching several FileHandlers to a named logger to write the log messages to specific files. I see that this creates a lck (lock) file for each log file. The lock file is deleted when I close and remove the FileHandler from the named Logger.

When is it best to close the FileHandler? Do I want to keep it open so that I don't have to instantiate it everytime I want to do some logging (which will result in the lock file hanging around) or should I close and recreate it each time so the lock file goes away (seems a bit heavy handed for logging).

Really a question about best practices. I have used log4j a lot so I am trying to get my head around the differences.

Thanks,

Ed

edwardborner
  • 227
  • 3
  • 10
  • What OS is this on? I don't get lock files with our log files. Is this to NFS or something? In any case I see no reason why you have to close and reopen your FileHandlers. Is there some reason why you are worried about the `.lck` files? – Gray Oct 29 '11 at 01:32

1 Answers1

2

As Gray mentioned, there is usually no reason to close and reopen FileHandlers.

If the .lck do not disapear after you close the program, you could try closing the Filehandlers in a Thread and add it as a Shutdown Hook with Runtime.getRuntime().addShutdownHook().

seeker
  • 671
  • 7
  • 13