001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package org.slf4j.impl;
015
016import org.junit.After;
017import org.junit.Before;
018import org.junit.Test;
019import org.slf4j.Logger;
020import org.slf4j.LoggerFactory;
021import org.slf4j.LoggerFactoryFriend;
022
023import ch.qos.logback.classic.ClassicConstants;
024import ch.qos.logback.classic.LoggerContext;
025import ch.qos.logback.core.testUtil.RandomUtil;
026import ch.qos.logback.core.testUtil.StatusChecker;
027import ch.qos.logback.core.util.StatusPrinter;
028
029public class RecursiveInitializationTest {
030
031    int diff = RandomUtil.getPositiveInt();
032
033    @Before
034    public void setUp() throws Exception {
035        System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, "recursiveInit.xml");
036        LoggerFactoryFriend.reset();
037    }
038
039    @After
040    public void tearDown() throws Exception {
041        System.clearProperty(ClassicConstants.CONFIG_FILE_PROPERTY);
042    }
043
044    @Test
045    public void recursiveLogbackInitialization() {
046        Logger logger = LoggerFactory.getLogger("RecursiveInitializationTest" + diff);
047        logger.info("RecursiveInitializationTest");
048
049        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
050        StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
051        StatusChecker statusChecker = new StatusChecker(loggerContext);
052        statusChecker.assertIsErrorFree();
053    }
054
055}