summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2018-12-12 17:16:30 -0600
committerInstrumental <jonathan.gathman@att.com>2018-12-12 17:16:52 -0600
commit218728980874ca82b07a10fceb26debd6045d2ea (patch)
tree16be83eb05dc48dcc5208ed6d2950991be5fade3 /misc
parentd499a5481bf34b6dfed090efb8c6d78822373e77 (diff)
Further Batch Refactor
Issue-ID: AAF-670 Change-Id: Ie68280edb7e9d6c495d3905de61372be895dcf3d Signed-off-by: Instrumental <jonathan.gathman@att.com>
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);
}
}