1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.slf4j.implTest;
15
16 import org.junit.jupiter.api.AfterEach;
17 import org.junit.jupiter.api.BeforeEach;
18 import org.junit.jupiter.api.Test;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.slf4j.LoggerFactoryFriend;
22
23 import ch.qos.logback.classic.ClassicConstants;
24 import ch.qos.logback.classic.LoggerContext;
25 import ch.qos.logback.core.testUtil.RandomUtil;
26 import ch.qos.logback.core.status.testUtil.StatusChecker;
27 import ch.qos.logback.core.util.StatusPrinter;
28
29 public class RecursiveInitializationTest {
30
31 int diff = RandomUtil.getPositiveInt();
32
33 @BeforeEach
34 public void setUp() throws Exception {
35 System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, "recursiveInit.xml");
36 LoggerFactoryFriend.reset();
37 }
38
39 @AfterEach
40 public void tearDown() throws Exception {
41 System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
42 }
43
44 @Test
45 public void recursiveLogbackInitialization() {
46 Logger logger = LoggerFactory.getLogger("RecursiveInitializationTest" + diff);
47 logger.info("RecursiveInitializationTest");
48
49 LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
50 StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
51 StatusChecker statusChecker = new StatusChecker(loggerContext);
52 statusChecker.assertIsErrorFree();
53 }
54
55 }