summaryrefslogtreecommitdiffstats
path: root/misc/log4j/src/main
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2019-05-29 04:58:50 -0500
committerInstrumental <jonathan.gathman@att.com>2019-05-29 07:34:28 -0500
commitff1417ff60baee231a28272f9a16ef2c9c8ea0a2 (patch)
treed9ca6c5f9661a3ffd6263d1380812e2430d9b230 /misc/log4j/src/main
parenta47bd51641efcb84e19d68a6383f0947df826636 (diff)
Post Init Service Starter
minor fixes Remove JU generated garbage files Issue-ID: AAF-835 Change-Id: I476291f1f1140f0640ed49452f8a5dabb28d9c30 Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'misc/log4j/src/main')
-rw-r--r--misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java25
1 files changed, 14 insertions, 11 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 e118baaa..9a615fb8 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
@@ -23,12 +23,9 @@ package org.onap.aaf.misc.env.log4j;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.Date;
public class LogFileNamer {
private final String root;
- private final String ending;
private final String dir;
public LogFileNamer(final String dir, final String root) {
@@ -38,14 +35,14 @@ public class LogFileNamer {
} else {
this.root = root + "-";
}
- ending = new SimpleDateFormat("YYYYMMdd").format(new Date());
}
public LogFileNamer noPID() {
return this;
}
- private static final String FILE_FORMAT_STR = "%s/%s%s%s_%d.log";
+ private static final String FIRST_FILE_FORMAT_STR = "%s/%s%s.log";
+ private static final String FILE_FORMAT_STR = "%s/%s%s.%d.log";
/**
* Accepts a String. If Separated by "|" then first part is the Appender name,
@@ -59,13 +56,19 @@ public class LogFileNamer {
* @throws IOException
*/
public String setAppender(String appender) throws IOException {
- int i = 0;
- File f;
- while ((f = new File(String.format(FILE_FORMAT_STR, dir, root, appender, ending, i))).exists()) {
- ++i;
- }
+ File f = new File(String.format(FIRST_FILE_FORMAT_STR, dir, root, appender));
+ if(f.exists()) {
+ int i = 0;
+ while ((f = new File(String.format(FILE_FORMAT_STR, dir, root, appender, i))).exists()) {
+ ++i;
+ }
+ }
- f.createNewFile();
+ try {
+ f.createNewFile();
+ } catch (IOException e) {
+ throw new IOException("Cannot create file '" + f.getCanonicalPath() + '\'', e);
+ }
System.setProperty("LOG4J_FILENAME_" + appender, f.getCanonicalPath());
return appender;
}