NARU NARU - 1 year ago 96
Java Question

couldn't get lock for .log file in Java

I am using Logger from Restlet framework with FileHandler to log my application in production mode. However, I always get the Excetption "Unable to create a FileHandler for the Logger: Couldn't get lock for test.log". How can I solve this?
Here is the code:

FileHandler aFileHandler = new FileHandler("test.log");

Formatter aFormatter = new SimpleFormatter();




This log file is used by several by more than one process at the same time.

And except the .log file, a lot of other files like ".log.1, .log.2 ....." have been created. Does anybody know why?

Answer Source

You should provide full Class Names. Logger & FileHandler are ambiguous. However I guess you are using some kind of logger maybe Log4j and a RollingFileAppender which is why your files are getting rotated i.e. xxx.log.1 & xxx.log.2. Your file is being used by some other process/application which is why you are not able to get a lock on that file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download