views:

180

answers:

3

I am trying to use Java Logger. I get my logger file (name.log) with the content I wish but I also get empty name.log.lck file. Why this file appears and how I can remove this behavior. Thank you in advance.

+1  A: 

".lck" sounds suspiciously like a lock file. You didn't say which logger you use but at elast one of them uses .lck files for locks - see this reply:

When the log file is created, a separet lock file called (in your case) "dbslogfile.txt.lck" is also created. The Logger uses this as a mutual exclusion mechanism for access to the actual log file. It doesn't seem to have been able to create it (it would have to create the lock file before the log file, of course).

DVK
+1  A: 

lock files are commonly used in Unix/Linux to ensure exclusive or serial access to an important resource.

In this case, the resource is the log file itself--you wouldn't want two or more logger instances trying to write to the same log file at the same time. That would not work out well at all. More about file locking

As Peter Barrett says about the Java Logger:

When the log file is created, a separate lock file called (in your case) "dbslogfile.txt.lck" is also created. The Logger uses this as a mutual exclusion mechanism for access to the actual log file.

Larry K
A: 

Hi friend as per my observation .lck is used by the handler(file handler) to lock the file in order to delete this file you need to close Handler that are associated with that logger object ,before you close your program....hope this will help you...here is sample lines how you can close associated handler

for(Handler h:log.getHandlers()) { h.close(); }

Rana