SOLR-10628: Fix test failures due to global log level change

This commit is contained in:
Jan Høydahl 2017-08-30 15:43:30 +02:00
parent b4c6bfafdb
commit c4a1bd52e9
2 changed files with 19 additions and 1 deletions

View File

@ -112,4 +112,18 @@ public final class StartupLoggingUtils {
log.warn("{} Dynamic log manipulation currently only supported for Log4j. "
+ "Please consult your logging framework of choice on how to configure the appropriate logging.", msg);
}
/**
* Return a string representing the current static ROOT logging level
* @return a string TRACE, DEBUG, WARN, ERROR or INFO representing current log level. Default is INFO
*/
public static String getLogLevelString() {
final Logger rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (rootLogger.isTraceEnabled()) return "TRACE";
else if (rootLogger.isDebugEnabled()) return "DEBUG";
else if (rootLogger.isInfoEnabled()) return "INFO";
else if (rootLogger.isWarnEnabled()) return "WARN";
else if (rootLogger.isErrorEnabled()) return "ERROR";
else return "INFO";
}
}

View File

@ -122,6 +122,7 @@ import org.apache.solr.util.RandomizeSSL.SSLRandomizer;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
import org.apache.solr.util.SSLTestConfig;
import org.apache.solr.util.StartupLoggingUtils;
import org.apache.solr.util.TestHarness;
import org.apache.solr.util.TestInjection;
import org.apache.zookeeper.KeeperException;
@ -180,6 +181,8 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
public static int DEFAULT_CONNECTION_TIMEOUT = 60000; // default socket connection timeout in ms
private static String initialRootLogLevel;
protected void writeCoreProperties(Path coreDirectory, String corename) throws IOException {
Properties props = new Properties();
props.setProperty("name", corename);
@ -251,7 +254,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
@BeforeClass
public static void setupTestCases() {
initialRootLogLevel = StartupLoggingUtils.getLogLevelString();
initClassLogLevels();
initCoreDataDir = createTempDir("init-core-data").toFile();
@ -321,6 +324,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
LogLevel.Configurer.restoreLogLevels(savedClassLogLevels);
savedClassLogLevels.clear();
StartupLoggingUtils.changeLogLevel(initialRootLogLevel);
}
/**