- /**\r
- * Accepts a String. If Separated by "|" then first part is the Appender name,\r
- * and the second is used in the FileNaming (This is to allow for shortened\r
- * Logger names, and more verbose file names) ONAP: jna code has license issues.\r
- * Just do Date + Unique Number\r
- * \r
- * @param appender\r
- * \r
- * returns the String Appender\r
- * @throws IOException\r
- */\r
- public String setAppender(String appender) throws IOException {\r
- int i = 0;\r
- File f;\r
- while ((f = new File(String.format(FILE_FORMAT_STR, dir, root, appender, ending, i))).exists()) {\r
- ++i;\r
- }\r
- \r
- f.createNewFile();\r
- System.setProperty("LOG4J_FILENAME_" + appender, f.getCanonicalPath());\r
- return appender;\r
- }\r
+ /**\r
+ * Accepts a String. If Separated by "|" then first part is the Appender name,\r
+ * and the second is used in the FileNaming (This is to allow for shortened\r
+ * Logger names, and more verbose file names) ONAP: jna code has license issues.\r
+ * Just do Date + Unique Number\r
+ * \r
+ * @param appender\r
+ * \r
+ * returns the String Appender\r
+ * @throws IOException\r
+ */\r
+ public String setAppender(String appender) throws IOException {\r
+ File f = new File(String.format(FIRST_FILE_FORMAT_STR, dir, root, appender));\r
+ File lock = new File(f.getAbsoluteFile()+".lock");\r
+ if(f.exists()) {\r
+ if(lock.exists()) {\r
+ int i = 0;\r
+ while ((f = new File(String.format(FILE_FORMAT_STR, dir, root, appender, i))).exists() &&\r
+ (lock = new File(f.getAbsoluteFile()+".lock")).exists()) {\r
+ ++i;\r
+ }\r
+ }\r
+ }\r
+ \r
+ try {\r
+ lock.createNewFile();\r
+ lock.deleteOnExit();\r
+ f.createNewFile();\r
+ } catch (IOException e) {\r
+ throw new IOException("Cannot create file '" + f.getCanonicalPath() + '\'', e);\r
+ }\r
+ System.setProperty("LOG4J_FILENAME_" + appender, f.getCanonicalPath());\r
+ return appender;\r
+ }\r