Implemented basic MDC encoding

This commit is contained in:
Collin Smith 2020-08-26 11:40:43 -07:00
parent 290160d93d
commit ddae4b9f75

View File

@ -1,6 +1,7 @@
package com.riiablo.logger;
import java.io.OutputStream;
import org.apache.commons.collections4.OrderedMap;
import org.apache.commons.lang3.exception.ExceptionUtils;
public class RiiabloEncoder extends SimpleEncoder {
@ -9,7 +10,9 @@ public class RiiabloEncoder extends SimpleEncoder {
@Override
public void encode(LogEvent event, OutputStream out) {
try {
final OrderedMap<String, String> mdc = event.mdc();
encodeMessage(event, buffer);
encodeMDC(mdc, buffer);
out.write(buffer.toString().getBytes(US_ASCII));
newLine(out);
} catch (Throwable t) {
@ -18,4 +21,10 @@ public class RiiabloEncoder extends SimpleEncoder {
buffer.setLength(0);
}
}
private void encodeMDC(OrderedMap<String, String> mdc, StringBuilder buffer) {
if (mdc.isEmpty()) return;
buffer.append(' ');
buffer.append(mdc.toString());
}
}