PatternLayoutTest.java (logback-1.2.3) | : | PatternLayoutTest.java (logback-v_1.2.7) | ||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
import ch.qos.logback.classic.joran.JoranConfigurator; | import ch.qos.logback.classic.joran.JoranConfigurator; | |||
import ch.qos.logback.classic.pattern.ConverterTest; | import ch.qos.logback.classic.pattern.ConverterTest; | |||
import ch.qos.logback.classic.spi.ILoggingEvent; | import ch.qos.logback.classic.spi.ILoggingEvent; | |||
import ch.qos.logback.classic.spi.LoggingEvent; | import ch.qos.logback.classic.spi.LoggingEvent; | |||
import ch.qos.logback.classic.testUtil.SampleConverter; | import ch.qos.logback.classic.testUtil.SampleConverter; | |||
import ch.qos.logback.core.Context; | import ch.qos.logback.core.Context; | |||
import ch.qos.logback.core.joran.spi.JoranException; | import ch.qos.logback.core.joran.spi.JoranException; | |||
import ch.qos.logback.core.pattern.PatternLayoutBase; | import ch.qos.logback.core.pattern.PatternLayoutBase; | |||
import ch.qos.logback.core.pattern.parser.AbstractPatternLayoutBaseTest; | import ch.qos.logback.core.pattern.parser.AbstractPatternLayoutBaseTest; | |||
import ch.qos.logback.core.testUtil.FileTestUtil; | ||||
import ch.qos.logback.core.testUtil.RandomUtil; | ||||
import ch.qos.logback.core.testUtil.StringListAppender; | import ch.qos.logback.core.testUtil.StringListAppender; | |||
import ch.qos.logback.core.util.OptionHelper; | import ch.qos.logback.core.util.OptionHelper; | |||
import ch.qos.logback.core.util.StatusPrinter; | import ch.qos.logback.core.util.StatusPrinter; | |||
import org.junit.Before; | import org.junit.Before; | |||
import org.junit.Test; | import org.junit.Test; | |||
import org.slf4j.MDC; | import org.slf4j.MDC; | |||
import static ch.qos.logback.classic.ClassicTestConstants.ISO_REGEX; | import static ch.qos.logback.classic.ClassicTestConstants.ISO_REGEX; | |||
import static ch.qos.logback.classic.ClassicTestConstants.MAIN_REGEX; | import static ch.qos.logback.classic.ClassicTestConstants.MAIN_REGEX; | |||
import static org.junit.Assert.*; | import static org.junit.Assert.*; | |||
skipping to change at line 242 | skipping to change at line 244 | |||
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "pattern/replaceNewl ine.xml"); | configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "pattern/replaceNewl ine.xml"); | |||
StatusPrinter.print(lc); | StatusPrinter.print(lc); | |||
root.getAppender("LIST"); | root.getAppender("LIST"); | |||
String msg = "A\nC"; | String msg = "A\nC"; | |||
logger.debug(msg); | logger.debug(msg); | |||
StringListAppender<ILoggingEvent> sla = (StringListAppender<ILoggingEven t>) root.getAppender("LIST"); | StringListAppender<ILoggingEvent> sla = (StringListAppender<ILoggingEven t>) root.getAppender("LIST"); | |||
assertNotNull(sla); | assertNotNull(sla); | |||
assertEquals(1, sla.strList.size()); | assertEquals(1, sla.strList.size()); | |||
assertEquals("A\n\tC", sla.strList.get(0)); | assertEquals("A\n\tC", sla.strList.get(0)); | |||
} | } | |||
@Test | ||||
public void prefixConverterSmoke() { | ||||
String pattern = "%prefix(%logger) %message"; | ||||
pl.setPattern(pattern); | ||||
pl.start(); | ||||
String val = pl.doLayout(makeLoggingEvent("hello", null)); | ||||
assertEquals("logger="+logger.getName() + " hello", val); | ||||
} | ||||
@Test | ||||
public void prefixConverterWithMDC() { | ||||
String mdcKey = "boo"; | ||||
String mdcVal = "moo"; | ||||
String pattern = "%prefix(%level %logger %X{"+mdcKey+"}) %message"; | ||||
pl.setPattern(pattern); | ||||
pl.start(); | ||||
MDC.put(mdcKey, mdcVal); | ||||
try { | ||||
String val = pl.doLayout(makeLoggingEvent("hello", null)); | ||||
assertEquals("level="+"INFO logger="+logger.getName() +" "+mdcKey+ | ||||
"="+mdcVal+ " hello", val); | ||||
} finally { | ||||
MDC.remove(mdcKey); | ||||
} | ||||
} | ||||
@Test | ||||
public void prefixConverterWithProperty() { | ||||
try { | ||||
String propertyKey = "px1953"; | ||||
String propertyVal = "pxVal"; | ||||
System.setProperty(propertyKey, propertyVal); | ||||
String pattern = "%prefix(%logger %property{"+propertyKey+"}) %m | ||||
essage"; | ||||
pl.setPattern(pattern); | ||||
pl.start(); | ||||
String val = pl.doLayout(makeLoggingEvent("hello", null)); | ||||
assertEquals("logger="+logger.getName() +" "+propertyKey+"="+prope | ||||
rtyVal+ " hello", val); | ||||
} finally { | ||||
System.clearProperty("px"); | ||||
} | ||||
} | ||||
} | } | |||
End of changes. 2 change blocks. | ||||
0 lines changed or deleted | 56 lines changed or added |