From 218728980874ca82b07a10fceb26debd6045d2ea Mon Sep 17 00:00:00 2001 From: Instrumental Date: Wed, 12 Dec 2018 17:16:30 -0600 Subject: Further Batch Refactor Issue-ID: AAF-670 Change-Id: Ie68280edb7e9d6c495d3905de61372be895dcf3d Signed-off-by: Instrumental --- .../main/java/org/onap/aaf/misc/env/LogTarget.java | 65 +++++++++------------- 1 file changed, 25 insertions(+), 40 deletions(-) (limited to 'misc/env/src/main/java/org') 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 -- cgit 1.2.3-korg