1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.pattern;
15
16 import ch.qos.logback.classic.Level;
17 import ch.qos.logback.classic.Logger;
18 import ch.qos.logback.classic.LoggerContext;
19 import ch.qos.logback.classic.PatternLayout;
20 import ch.qos.logback.classic.spi.ILoggingEvent;
21 import ch.qos.logback.classic.spi.LoggingEvent;
22 import ch.qos.logback.core.status.testUtil.StatusChecker;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27
28
29 public class CompositeConverterTest {
30
31 private PatternLayout pl = new PatternLayout();
32 private LoggerContext lc = new LoggerContext();
33 Logger logger = lc.getLogger(this.getClass());
34 StatusChecker sc = new StatusChecker(lc);
35
36
37 @BeforeEach
38 public void setUp() {
39 pl.setContext(lc);
40 }
41
42 ILoggingEvent makeLoggingEvent(String msg, Exception ex) {
43 return new LoggingEvent(CompositeConverterTest.class.getName(), logger, Level.INFO, msg, ex, null);
44 }
45
46
47
48 @Test
49 public void testLogback1582() {
50
51
52 pl.setPattern("%m %replace(%rootException{5, EVAL_REF}){'\\n', 'XYZ'}\"");
53 pl.start();
54 ILoggingEvent le = makeLoggingEvent("assert", new Exception("test"));
55
56 String result = pl.doLayout(le);
57 sc.assertIsErrorFree();
58 assertTrue(result.contains("XYZ"));
59 }
60
61 }