mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-20 09:17:29 +07:00
Implemented API for controlling full vs compact encoder modes
This commit is contained in:
parent
ddae4b9f75
commit
4d0ea7188f
@ -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(' ');
|
||||
|
Loading…
Reference in New Issue
Block a user