summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorvarun gudisena <varuneshwar.gudisena@att.com>2018-12-12 23:35:04 +0000
committerGerrit Code Review <gerrit@onap.org>2018-12-12 23:35:04 +0000
commit1321c6e63c90a40fad36d2a4a3fef912b4169130 (patch)
tree3b18e5dc0ed6812b3c27cd529702dfa71bdb3942 /misc
parentdf63855ff6362e059bc33d84d3a27d0d92150116 (diff)
parent218728980874ca82b07a10fceb26debd6045d2ea (diff)
Merge "Further Batch Refactor"
Diffstat (limited to 'misc')
-rw-r--r--misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java65
-rw-r--r--misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java8
2 files changed, 29 insertions, 44 deletions
diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java b/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java
index f2b539a3..84eb5ee6 100644
--- a/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java
+++ b/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java
@@ -63,10 +63,26 @@ public interface LogTarget {
};
// A Convenient LogTarget to write to the Console
- public static final LogTarget SYSOUT = new LogTarget() {
+ public static final LogTarget SYSOUT = new StreamLogTarget(System.out,false);
+
+ // A Convenient LogTarget to write to the Console
+ public static final LogTarget SYSERR = new StreamLogTarget(System.err,false);
+
+ public static class StreamLogTarget implements LogTarget {
+ private final PrintStream out;
+ private final boolean closeMe;
+
+ public StreamLogTarget(PrintStream ps) {
+ this(ps,true);
+ }
+
+ /* Do NOT close SYSTEM ERR or OUT*/
+ protected StreamLogTarget(PrintStream ps, boolean shouldClose) {
+ out = ps;
+ closeMe = shouldClose;
+ }
public void log(Object ... msgs) {
- PrintStream out = System.out;
- out.print(org.onap.aaf.misc.env.util.Chrono.dateFmt.format(new Date()));
+ out.print(Chrono.dateFmt.format(new Date()));
out.print(": ");
for (Object str : msgs) {
if (str!=null) {
@@ -80,7 +96,6 @@ public interface LogTarget {
}
public void log(Throwable t, Object ... msgs) {
- PrintStream out = System.out;
out.print(Chrono.dateFmt.format(new Date()));
out.print(": ");
for (Object str : msgs) {
@@ -100,43 +115,13 @@ public interface LogTarget {
public void printf(String fmt, Object ... vars) {
log(String.format(fmt,vars));
}
- };
-
- // A Convenient LogTarget to write to the Console
- public static final LogTarget SYSERR = new LogTarget() {
- public void log(Object ... msgs) {
- PrintStream out = System.err;
- out.print(Chrono.dateFmt.format(new Date()));
- out.print(": ");
- for (Object str : msgs) {
- out.print(str.toString());
- out.print(' ');
- }
- out.println();
- out.flush();
- }
-
- public void log(Throwable t, Object ... msgs) {
- PrintStream out = System.err;
- out.print(Chrono.dateFmt.format(new Date()));
- out.print(": ");
- for (Object str : msgs) {
- out.print(str.toString());
- out.print(' ');
- }
- out.println();
- t.printStackTrace(out);
- }
-
- public boolean isLoggable() {
- return true;
+
+ public void close() {
+ if(closeMe) {
+ out.close();
+ }
}
- @Override
- public void printf(String fmt, Object ... vars) {
- log(String.format(fmt,vars));
- }
-
- };
+ }
}; \ No newline at end of file
diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java
index c679d11e..2388964f 100644
--- a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java
+++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java
@@ -65,9 +65,9 @@ public class JU_LogTargetTest {
outTarget.log(t);
outTarget.log(t, "First String Object");
- assertTrue(outTarget.isLoggable());
+ assertTrue(outTarget.isLoggable());
- verify(t, times(2)).printStackTrace(System.out);
+ verify(t, times(2)).printStackTrace(System.out);
}
@Test
@@ -80,9 +80,9 @@ public class JU_LogTargetTest {
errTarget.log(t);
errTarget.log(t, "First String Object");
- assertTrue(errTarget.isLoggable());
+ assertTrue(errTarget.isLoggable());
- verify(t, times(2)).printStackTrace(System.err);
+ verify(t, times(2)).printStackTrace(System.err);
}
}