Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

couldn't get lock for .log file in Java

Tags:

java

logging

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();

aFileHandler.setFormatter(aFormatter);

aLogger.setLevel(Level.ALL);

aLogger.addHandler(aFileHandler);

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?

like image 658
NARU Avatar asked Apr 18 '11 09:04

NARU


1 Answers

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.

like image 59
Abhishek Avatar answered Sep 25 '22 14:09

Abhishek