Summary: | Intermittently Log4j fails to bind with log file | ||
---|---|---|---|
Product: | Log4j - Now in Jira | Reporter: | chirag desai <chirag.desai> |
Component: | Appender | Assignee: | log4j-dev <log4j-dev> |
Status: | NEW --- | ||
Severity: | critical | ||
Priority: | P2 | ||
Version: | 1.2 | ||
Target Milestone: | 1.2.18 | ||
Hardware: | Sun | ||
OS: | Solaris |
Description
chirag desai
2010-08-03 10:53:11 UTC
Have you tested with a newer version of Log4j? The latest is 1.2.16. It's entirely possible this used to be an issue, but has since been fixed. Jake Hi, I came accross this issue while researching a similar behavior on our systems. When rolling at midnight (using companions, we create a folder based on date) we intermittently lose the logs. Bascially the appender gets broken in a way a no new log file is created. Looking at the code there is a race condition in FileAppender in the following block: String parentName = new File(fileName).getParent(); if (parentName != null) { File parentDir = new File(parentName); if ((!parentDir.exists()) && (parentDir.mkdirs())) ostream = new FileOutputStream(fileName, append); else throw ex; } This is run when a new folder structure must be created by the appender. If two different appenders try to create the parent directory at the same time, then both will get "false" when testing for parent dir existence, but only one will get "true" upon directory creation. The second appender will then fail and rethrow the original exception, and log4j presumably closes the appender after that, which prevents any further attempt to write to the appender. Only solution so far is to reload log4j configuration. My assumption is that this code tries to protect against errors while trying to create the directories. To keep the protection a double check pattern should be added to re-test for parent dir existence and only fail if it does not exist during the second test. Another option would be to synchronize on a static monitor object at the FileAppender level so that two different appenders could not enter that section at the same time. Even easier actually, change the code to: if (!parentDir.exists())) { parentDir.mkdirs(); } ostream = new FileOutputStream(fileName, append); And the stream constructor will throw again an exception it it has to. |