View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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  }