final String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
// set up appender
final PatternLayout layout = PatternLayout.createLayout(msgPattern, ctx.getConfiguration(), null, null, null, null);
// FileOutputStream fos = new FileOutputStream(OUTPUT_FILE + "_mdc");
final FileAppender appender = FileAppender.createAppender(OUTPUT_FILE + "_mdc", "false", "false", "File",
"false", "true", "false", null, layout, null, "false", null, null);
appender.start();
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
// output starting message
root.debug("starting mdc pattern test");
layout.setConversionPattern(mdcMsgPattern1);
root.debug("empty mdc, no key specified in pattern");
layout.setConversionPattern(mdcMsgPattern2);
root.debug("empty mdc, key1 in pattern");
layout.setConversionPattern(mdcMsgPattern3);
root.debug("empty mdc, key2 in pattern");
layout.setConversionPattern(mdcMsgPattern4);
root.debug("empty mdc, key3 in pattern");
layout.setConversionPattern(mdcMsgPattern5);
root.debug("empty mdc, key1, key2, and key3 in pattern");
ThreadContext.put("key1", "value1");
ThreadContext.put("key2", "value2");
layout.setConversionPattern(mdcMsgPattern1);
root.debug("filled mdc, no key specified in pattern");
layout.setConversionPattern(mdcMsgPattern2);
root.debug("filled mdc, key1 in pattern");
layout.setConversionPattern(mdcMsgPattern3);
root.debug("filled mdc, key2 in pattern");
layout.setConversionPattern(mdcMsgPattern4);
root.debug("filled mdc, key3 in pattern");
layout.setConversionPattern(mdcMsgPattern5);
root.debug("filled mdc, key1, key2, and key3 in pattern");
ThreadContext.remove("key1");
ThreadContext.remove("key2");
layout.setConversionPattern(msgPattern);
root.debug("finished mdc pattern test");
assertTrue(Compare.compare(this.getClass(), OUTPUT_FILE + "_mdc", WITNESS_FILE + "_mdc"));
root.removeAppender(appender);
appender.stop();
}