|
11 | 11 |
|
12 | 12 | //import org.apache.commons.io.FileUtils;
|
13 | 13 | //import org.apache.commons.lang3.RandomStringUtils;
|
| 14 | +import ch.qos.logback.classic.util.LogbackMDCAdapter; |
14 | 15 | import org.junit.jupiter.api.AfterEach;
|
15 | 16 | import org.junit.jupiter.api.Assertions;
|
| 17 | +import org.junit.jupiter.api.BeforeEach; |
16 | 18 | import org.junit.jupiter.api.Test;
|
17 | 19 | import org.slf4j.Logger;
|
18 | 20 | import org.slf4j.LoggerFactory;
|
|
21 | 23 | import ch.qos.logback.classic.LoggerContext;
|
22 | 24 | import ch.qos.logback.classic.joran.JoranConfigurator;
|
23 | 25 | import ch.qos.logback.core.joran.spi.JoranException;
|
| 26 | +import org.slf4j.spi.MDCAdapter; |
24 | 27 |
|
25 | 28 | public class LogbackListenerTest {
|
26 | 29 | private File logFile = new File("target/test.log");
|
27 | 30 |
|
| 31 | + LoggerContext loggerContext = new LoggerContext(); |
| 32 | + LogbackMDCAdapter mdcAdapter = new LogbackMDCAdapter(); |
| 33 | + |
| 34 | + @BeforeEach |
| 35 | + void setUp() { |
| 36 | + loggerContext.setMDCAdapter(mdcAdapter); |
| 37 | + } |
| 38 | + |
28 | 39 | private void doConfigure() throws JoranException {
|
29 |
| - LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); |
30 | 40 | JoranConfigurator configurator = new JoranConfigurator();
|
31 |
| - configurator.setContext(context); |
| 41 | + configurator.setContext(loggerContext); |
32 | 42 | configurator.doConfigure(new File("src/test/input/issue/logback-1159.xml"));
|
33 | 43 | }
|
34 | 44 |
|
35 | 45 | @AfterEach
|
36 | 46 | public void after() {
|
37 | 47 | logFile.delete();
|
38 |
| - LoggerFactoryFriend.reset(); |
39 | 48 | }
|
40 | 49 |
|
41 | 50 | private void disableLogFileAccess() throws IOException {
|
|
0 commit comments