From abf7c0e407c97250c07d408c314c5aa1c757263e Mon Sep 17 00:00:00 2001 From: Instrumental Date: Tue, 3 Apr 2018 21:30:32 -0500 Subject: Create method of Logging to O/S from Container Issue-ID: AAF-211 Change-Id: Ib5c369c24082823f6f8cfde7609b966f57085665 Signed-off-by: Instrumental --- .../src/main/java/org/onap/aaf/cadi/Access.java | 2 +- .../main/java/org/onap/aaf/cadi/PropAccess.java | 34 +++++++++++++--------- .../core/src/main/java/org/onap/aaf/cadi/Symm.java | 3 +- .../main/java/org/onap/aaf/cadi/config/Config.java | 2 ++ .../java/org/onap/aaf/cadi/test/JU_Access.java | 2 +- .../java/org/onap/aaf/cadi/test/JU_CmdLine.java | 27 +++++++++++++++-- 6 files changed, 51 insertions(+), 19 deletions(-) (limited to 'cadi/core') diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java index 7a9e63be..83127238 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java @@ -37,7 +37,7 @@ import java.util.Properties; public interface Access { // levels to use public enum Level { - DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),NONE(0XFFFF); + DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),TRACE(0x10000),NONE(0XFFFF); private final int bit; Level(int ord) { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java index bd1ad72d..c827477f 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java @@ -31,12 +31,11 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map.Entry; +import java.util.Properties; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.config.SecurityInfo; -import java.util.Properties; - public class PropAccess implements Access { // Sonar says cannot be static... it's ok. not too many PropAccesses created. private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); @@ -70,18 +69,11 @@ public class PropAccess implements Access { public PropAccess(PrintStream ps, String[] args) { logIt = new StreamLogIt(ps==null?System.out:ps); - Properties nprops=new Properties(); - int eq; - for(String arg : args) { - if((eq=arg.indexOf('='))>0) { - nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1)); - } - } - init(nprops); + init(logIt,args); } public PropAccess(LogIt logit, String[] args) { - logIt = logit; + init(logit, args); } public PropAccess(Properties p) { @@ -93,6 +85,18 @@ public class PropAccess implements Access { init(p); } + protected void init(final LogIt logIt, final String[] args) { + this.logIt = logIt; + Properties nprops=new Properties(); + int eq; + for(String arg : args) { + if((eq=arg.indexOf('='))>0) { + nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1)); + } + } + init(nprops); + } + protected void init(Properties p) { // Make sure these two are set before any changes in Logging name = "cadi"; @@ -248,9 +252,13 @@ public class PropAccess implements Access { logIt.push(level,elements); } } - + protected StringBuilder buildMsg(Level level, Object[] elements) { - StringBuilder sb = new StringBuilder(iso8601.format(new Date())); + return buildMsg(name,iso8601,level,elements); + } + + public static StringBuilder buildMsg(final String name, final SimpleDateFormat sdf, Level level, Object[] elements) { + StringBuilder sb = new StringBuilder(sdf.format(new Date())); sb.append(' '); sb.append(level.name()); sb.append(" ["); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java index 65cb81a5..82645c31 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java @@ -452,7 +452,8 @@ public class Symm { switch(read) { case -1: case '=': - case '\n': + case '\n': + case '\r': return -1; } for(int i=0;i