1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic;
15
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.junit.jupiter.api.BeforeEach;
21
22 import ch.qos.logback.classic.pattern.ConverterTest;
23 import ch.qos.logback.classic.pattern.LineOfCallerConverter;
24 import ch.qos.logback.classic.spi.ILoggingEvent;
25 import ch.qos.logback.core.AppenderBase;
26 import ch.qos.logback.core.pattern.DynamicConverter;
27 import org.junit.jupiter.api.Test;
28
29 import static org.junit.jupiter.api.Assertions.assertEquals;
30
31 public class FluentAPILocationExtractionTest {
32 static public class WithLocationInfoListAppender extends AppenderBase<ILoggingEvent> {
33
34 DynamicConverter<ILoggingEvent> converter = new LineOfCallerConverter();
35 public List<String> list = new ArrayList<>();
36
37 protected void append(ILoggingEvent e) {
38 String val = converter.convert(e);
39 list.add(val);
40 }
41 }
42
43 LoggerContext lc = new LoggerContext();
44 Logger logger = lc.getLogger(ConverterTest.class);
45 WithLocationInfoListAppender wlila = new WithLocationInfoListAppender();
46
47 @BeforeEach
48 public void setUp() {
49 wlila.setContext(lc);
50 wlila.start();
51
52 logger.addAppender(wlila);
53 }
54
55 @Test
56 public void smoke() {
57 logger.addAppender(wlila);
58
59 logger.atInfo().log("smoke");
60
61 assertEquals(1, wlila.list.size());
62 String result = wlila.list.get(0);
63 assertEquals("59", result);
64 }
65
66 }