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");
- public static Level DEFAULT = Level.AUDIT;
+ public static final Level DEFAULT = Level.AUDIT;
private Symm symm;
private int level;
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) {
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";
String chainProp = props.getProperty(Config.CADI_PROP_FILES);
if(chainProp!=null) {
if(recursionProtection==null) {
- recursionProtection = new ArrayList<String>();
+ recursionProtection = new ArrayList<>();
recursionProtection.add(cadi_prop_files);
}
if(!recursionProtection.contains(chainProp)) {
Object value = es.getValue();
if(value instanceof String) {
String trim = ((String)value).trim();
+ // Remove Beginning/End Quotes, which might be there if mixed with Bash Props
+ int s = 0, e=trim.length()-1;
+ if(s<e && trim.charAt(s)=='"' && trim.charAt(e)=='"') {
+ trim=trim.substring(s+1,e);
+ }
if(trim!=value) { // Yes, I want OBJECT equals
props.setProperty((String)es.getKey(), trim);
}
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(" [");