From ddae4b9f751aa371094221e2064f66ea1250ade8 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 26 Aug 2020 11:40:43 -0700 Subject: [PATCH] Implemented basic MDC encoding --- core/src/com/riiablo/logger/RiiabloEncoder.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/com/riiablo/logger/RiiabloEncoder.java b/core/src/com/riiablo/logger/RiiabloEncoder.java index 288d8bf1..3bc2cf35 100644 --- a/core/src/com/riiablo/logger/RiiabloEncoder.java +++ b/core/src/com/riiablo/logger/RiiabloEncoder.java @@ -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 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 mdc, StringBuilder buffer) { + if (mdc.isEmpty()) return; + buffer.append(' '); + buffer.append(mdc.toString()); + } }