package org.onap.aaf.cadi;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
+import java.io.StringBufferInputStream;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
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");
+ private final SimpleDateFormat iso8601 = newISO8601();
+
+ public static SimpleDateFormat newISO8601() {
+ return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+ }
public static final Level DEFAULT = Level.AUDIT;
init(nprops);
}
- protected void init(Properties p) {
+ protected synchronized void init(Properties p) {
// Make sure these two are set before any changes in Logging
name = "cadi";
- level=DEFAULT.maskOf();
props = new Properties();
// First, load related System Properties
// Preset LogLevel
String sLevel = props.getProperty(Config.CADI_LOGLEVEL);
- if (sLevel!=null) {
- level=Level.valueOf(sLevel).maskOf();
- }
-
// Third, load any Chained Property Files
load(props.getProperty(Config.CADI_PROP_FILES));
if(sLevel==null) { // if LogLev wasn't set before, check again after Chained Load
sLevel = props.getProperty(Config.CADI_LOGLEVEL);
- if (sLevel!=null) {
+ if (sLevel==null) {
+ level=DEFAULT.maskOf();
+ } else {
level=Level.valueOf(sLevel).maskOf();
}
}
}
}
- protected StringBuilder buildMsg(Level level, Object[] elements) {
+ public StringBuilder buildMsg(Level level, Object[] elements) {
return buildMsg(name,iso8601,level,elements);
}
-
+
+ /*
+ * Need to pass in DateFormat per thread, because not marked as thread safe
+ */
public static StringBuilder buildMsg(final String name, final DateFormat sdf, Level level, Object[] elements) {
final StringBuilder sb;
int end = elements.length;
if (o!=null) {
if(o.getClass().isArray()) {
first = write(first,sb,(Object[])o);
+ } else if(o instanceof Throwable) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ ((Throwable)o).printStackTrace(ps);
+ sb.append(baos.toString());
} else {
s=o.toString();
if (first) {