use of org.spf4j.base.avro.StackSampleElement in project spf4j by zolyfarkas.
the class Slf4jLogRecord method toLogRecord.
@SuppressFBWarnings("WOC_WRITE_ONLY_COLLECTION_LOCAL")
default LogRecord toLogRecord(final String origin, final String ptraceId) {
java.lang.Throwable extraThrowable = this.getExtraThrowable();
Marker marker = this.getMarker();
Object[] extraArguments = this.getExtraArguments();
Map<String, Object> attribs = null;
List<Object> xArgs;
String traceId = ptraceId;
List<StackSampleElement> profiles = Collections.EMPTY_LIST;
if (extraArguments.length == 0) {
xArgs = Collections.emptyList();
} else {
int nrAttribs = 0;
for (Object obj : extraArguments) {
if (obj instanceof LogAttribute) {
LogAttribute la = (LogAttribute) obj;
String name = la.getName();
switch(name) {
case LogAttribute.ID_ATTR_NAME:
traceId = la.getValue().toString();
break;
case LogAttribute.PROFILE_SAMPLES_ATTR_NAME:
profiles = Converters.convert((StackSamples) la.getValue());
break;
default:
}
nrAttribs++;
}
}
if (nrAttribs == 0) {
xArgs = Arrays.asList(extraArguments);
} else {
if (nrAttribs == extraArguments.length) {
xArgs = Collections.EMPTY_LIST;
} else {
xArgs = new ArrayList<>(extraArguments.length - nrAttribs);
}
attribs = Maps.newHashMapWithExpectedSize(nrAttribs + (marker == null ? 0 : 1));
for (Object obj : extraArguments) {
if (obj instanceof LogAttribute) {
LogAttribute la = (LogAttribute) obj;
String aName = la.getName();
switch(aName) {
case LogAttribute.ID_ATTR_NAME:
case LogAttribute.PROFILE_SAMPLES_ATTR_NAME:
break;
default:
attribs.put(aName, la.getValue());
}
} else {
xArgs.add(obj);
}
}
if (marker != null) {
attribs.put(marker.getName(), marker);
}
}
}
int nrMsgArgs = this.getNrMessageArguments();
List<String> messageArgs;
if (nrMsgArgs == 0) {
messageArgs = Collections.emptyList();
} else {
Object[] args = this.getArguments();
String[] ma = new String[nrMsgArgs];
for (int i = 0; i < nrMsgArgs; i++) {
Object arg = args[i];
if (arg == null) {
ma[i] = "null";
} else {
ma[i] = ObjectAppenderSupplier.getDefaultToStringAppenderSupplier().get(arg.getClass()).toString(arg);
}
}
messageArgs = Arrays.asList(ma);
}
return new LogRecord(origin, traceId, this.getLevel().getAvroLevel(), Instant.ofEpochMilli(this.getTimeStamp()), this.getLoggerName(), this.getThreadName(), this.getMessageFormat(), messageArgs, xArgs, attribs == null ? Collections.emptyMap() : attribs, extraThrowable == null ? null : convert(extraThrowable), profiles);
}
Aggregations