diff options
Diffstat (limited to 'misc/log4j')
-rw-r--r-- | misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java | 30 | ||||
-rw-r--r-- | misc/log4j/src/test/java/org/onap/aaf/misc/env/log4j/JU_LogFileNamerTest.java | 80 |
2 files changed, 55 insertions, 55 deletions
diff --git a/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java b/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java index 85aae6f0..35d5038c 100644 --- a/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java +++ b/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java @@ -56,24 +56,24 @@ public class LogFileNamer { * @throws IOException
*/
public String setAppender(String appender) throws IOException {
- File f = new File(String.format(FIRST_FILE_FORMAT_STR, dir, root, appender));
- File lock = new File(f.getAbsoluteFile()+".lock");
- if(f.exists()) {
- if(lock.exists()) {
- int i = 0;
- while ((f = new File(String.format(FILE_FORMAT_STR, dir, root, appender, i))).exists() &&
- (lock = new File(f.getAbsoluteFile()+".lock")).exists()) {
- ++i;
- }
- }
- }
+ File f = new File(String.format(FIRST_FILE_FORMAT_STR, dir, root, appender));
+ File lock = new File(f.getAbsoluteFile()+".lock");
+ if(f.exists()) {
+ if(lock.exists()) {
+ int i = 0;
+ while ((f = new File(String.format(FILE_FORMAT_STR, dir, root, appender, i))).exists() &&
+ (lock = new File(f.getAbsoluteFile()+".lock")).exists()) {
+ ++i;
+ }
+ }
+ }
try {
- lock.createNewFile();
- lock.deleteOnExit();
- f.createNewFile();
+ lock.createNewFile();
+ lock.deleteOnExit();
+ f.createNewFile();
} catch (IOException e) {
- throw new IOException("Cannot create file '" + f.getCanonicalPath() + '\'', e);
+ throw new IOException("Cannot create file '" + f.getCanonicalPath() + '\'', e);
}
System.setProperty("LOG4J_FILENAME_" + appender, f.getCanonicalPath());
return appender;
diff --git a/misc/log4j/src/test/java/org/onap/aaf/misc/env/log4j/JU_LogFileNamerTest.java b/misc/log4j/src/test/java/org/onap/aaf/misc/env/log4j/JU_LogFileNamerTest.java index 8657e1d6..1aaeb7fb 100644 --- a/misc/log4j/src/test/java/org/onap/aaf/misc/env/log4j/JU_LogFileNamerTest.java +++ b/misc/log4j/src/test/java/org/onap/aaf/misc/env/log4j/JU_LogFileNamerTest.java @@ -38,55 +38,55 @@ public class JU_LogFileNamerTest { } private void cleanup(String name) { -// System.out.println("XXXX" + dir.getAbsolutePath()); - for(File f : dir.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.contains(name) && name.endsWith(".log"); - } - })) { -// System.out.println("Deleting " + f.getAbsolutePath()); - f.delete(); - }; +// System.out.println("XXXX" + dir.getAbsolutePath()); + for(File f : dir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.contains(name) && name.endsWith(".log"); + } + })) { +// System.out.println("Deleting " + f.getAbsolutePath()); + f.delete(); + }; } @Test public void test() throws IOException { - String name = "Append"; - try { - LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log"); - assertEquals(logFileNamer, logFileNamer.noPID()); - - logFileNamer.setAppender(name); - assertEquals(System.getProperty("LOG4J_FILENAME_Append"), - dir.getCanonicalFile() + File.separator + "log-" + name + ".log"); - - logFileNamer.setAppender(name); - assertEquals(System.getProperty("LOG4J_FILENAME_Append"), - dir.getCanonicalFile() + File.separator + "log-" + name + ".0.log"); - } finally { - cleanup("log-" + name); - } + String name = "Append"; + try { + LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log"); + assertEquals(logFileNamer, logFileNamer.noPID()); + + logFileNamer.setAppender(name); + assertEquals(System.getProperty("LOG4J_FILENAME_Append"), + dir.getCanonicalFile() + File.separator + "log-" + name + ".log"); + + logFileNamer.setAppender(name); + assertEquals(System.getProperty("LOG4J_FILENAME_Append"), + dir.getCanonicalFile() + File.separator + "log-" + name + ".0.log"); + } finally { + cleanup("log-" + name); + } } @Test public void testBlankRoot() throws IOException { - String name = "Different"; - try { - LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), ""); - assertEquals(logFileNamer, logFileNamer.noPID()); - - logFileNamer.setAppender(name); - assertEquals(System.getProperty("LOG4J_FILENAME_Different"), - dir.getCanonicalPath() + File.separator + name + ".log"); - - logFileNamer.setAppender(name); - assertEquals(System.getProperty("LOG4J_FILENAME_Different"), - dir.getCanonicalPath() + File.separator + name + ".0.log"); - } finally { - cleanup(name); - } + String name = "Different"; + try { + LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), ""); + assertEquals(logFileNamer, logFileNamer.noPID()); + + logFileNamer.setAppender(name); + assertEquals(System.getProperty("LOG4J_FILENAME_Different"), + dir.getCanonicalPath() + File.separator + name + ".log"); + + logFileNamer.setAppender(name); + assertEquals(System.getProperty("LOG4J_FILENAME_Different"), + dir.getCanonicalPath() + File.separator + name + ".0.log"); + } finally { + cleanup(name); + } } } |