PatternLayoutEscaped extends PatternLayout { @Override public String format(final LoggingEvent event) { if (event.getMessage() instanceof String) { return super.format(appendStackTraceToEvent(event)); } return super.format(event); } PatternLayoutEscaped(final String s);  PatternLayoutEscaped(); @Override String format(final LoggingEvent event);  }
@Test public void testWithException() { try { throw new Exception("This is an exception"); } catch (final Exception e) { final LoggingEvent event = createEventWithException("There was an exception", e); assertTrue(this.layout.format(event) .startsWith("There was an exception\\njava.lang.Exception: This is an exception")); } }
@Test public void testNewLine() { final LoggingEvent event = createMessageEvent("This message contains \n new lines"); assertTrue(this.layout.format(event).equals("This message contains \\n new lines")); }
@Test public void testQuote() { final LoggingEvent event = createMessageEvent("This message contains \" quotes"); assertTrue(this.layout.format(event).equals("This message contains \\\" quotes")); }
@Test public void testTab() { final LoggingEvent event = createMessageEvent("This message contains a tab \t"); assertTrue(this.layout.format(event).equals("This message contains a tab \\t")); }
@Test public void testBackSlash() { final LoggingEvent event = createMessageEvent("This message contains a backslash \\"); assertTrue(this.layout.format(event).equals("This message contains a backslash \\\\")); }