X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2FPropAccess.java;h=c827477fff3669152ba2979e463026e442a7981f;hb=abf7c0e407c97250c07d408c314c5aa1c757263e;hp=07e9b592df00ada88d83db523c5b0b5bc8e9cde4;hpb=a20accc73189d8e5454cd26049c0e6fae75da16f;p=aaf%2Fauthz.git 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 07e9b592..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,14 +31,14 @@ 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 { - private static final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + // 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"); public static Level DEFAULT = Level.AUDIT; @@ -69,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) { @@ -92,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"; @@ -247,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(" [");