/** * MulticolorLayout can throw if color name is not valid. * * @throws Exception If something goes wrong */ @Test(expected = IllegalArgumentException.class) public void throwsOnIllegalColorName() throws Exception { final MulticolorLayout layout = new MulticolorLayout(); layout.setConversionPattern("%color-oops{%p} %m"); final LoggingEvent event = Mockito.mock(LoggingEvent.class); Mockito.doReturn(Level.DEBUG).when(event).getLevel(); Mockito.doReturn("text").when(event).getRenderedMessage(); layout.format(event); }
/** * MulticolorLayout can render custom color. * * @throws Exception If something goes wrong */ @Test public void rendersCustomConstantColor() throws Exception { final MulticolorLayout layout = new MulticolorLayout(); layout.setConversionPattern("%color-red{%p} %m"); final LoggingEvent event = Mockito.mock(LoggingEvent.class); Mockito.doReturn(Level.DEBUG).when(event).getLevel(); Mockito.doReturn("foo").when(event).getRenderedMessage(); MatcherAssert.assertThat( StringEscapeUtils.escapeJava(layout.format(event)), Matchers.equalTo("\\u001B[31mDEBUG\\u001B[m foo")); }
/** * MulticolorLayout can transform event to text. * * @throws Exception If something goes wrong */ @Test public void transformsLoggingEventToText() throws Exception { final MulticolorLayout layout = new MulticolorLayout(); layout.setConversionPattern(MulticolorLayoutTest.CONV_PATTERN); final LoggingEvent event = Mockito.mock(LoggingEvent.class); Mockito.doReturn(Level.DEBUG).when(event).getLevel(); Mockito.doReturn("hello").when(event).getRenderedMessage(); MatcherAssert.assertThat( StringEscapeUtils.escapeJava(layout.format(event)), Matchers.equalTo("[\\u001B[2;37mDEBUG\\u001B[m] \\u001B[2;37mhello\\u001B[m")); }
/** * MulticolorLayout can transform event to text. * * @throws Exception If something goes wrong */ @Test public void overwriteDefaultColor() throws Exception { final MulticolorLayout layout = new MulticolorLayout(); layout.setConversionPattern(MulticolorLayoutTest.CONV_PATTERN); layout.setLevels("INFO:2;10"); final LoggingEvent event = Mockito.mock(LoggingEvent.class); Mockito.doReturn(Level.INFO).when(event).getLevel(); Mockito.doReturn("change").when(event).getRenderedMessage(); MatcherAssert.assertThat( StringEscapeUtils.escapeJava(layout.format(event)), Matchers.equalTo("[\\u001B[2;10mINFO\\u001B[m] \\u001B[2;10mchange\\u001B[m")); }