Implemented API for controlling full vs compact encoder modes

This commit is contained in:
Collin Smith 2020-08-26 11:46:28 -07:00
parent ddae4b9f75
commit 4d0ea7188f

View File

@ -7,12 +7,24 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
public class RiiabloEncoder extends SimpleEncoder {
private final StringBuilder buffer = new StringBuilder(1024);
private boolean fullMode;
public boolean isFullMode() {
return fullMode;
}
public void setFullMode(boolean b) {
this.fullMode = b;
}
@Override
public void encode(LogEvent event, OutputStream out) {
try {
final OrderedMap<String, String> mdc = event.mdc();
encodeMessage(event, buffer);
encodeMDC(mdc, buffer);
if (fullMode) {
encodeFullMode(event, buffer);
} else {
encodeCompactMode(event, buffer);
}
out.write(buffer.toString().getBytes(US_ASCII));
newLine(out);
} catch (Throwable t) {
@ -22,6 +34,16 @@ public class RiiabloEncoder extends SimpleEncoder {
}
}
private void encodeFullMode(LogEvent event, StringBuilder buffer) {
final OrderedMap<String, String> mdc = event.mdc();
encodeMessage(event, buffer);
encodeMDC(mdc, buffer);
}
private void encodeCompactMode(LogEvent event, StringBuilder buffer) {
encodeFullMode(event, buffer);
}
private void encodeMDC(OrderedMap<String, String> mdc, StringBuilder buffer) {
if (mdc.isEmpty()) return;
buffer.append(' ');