Apache Solr open-source search software
SOLR-10628: Fix test failures due to global log level change
Jan Høydahlc4a1bd52e9b9
diff --git a/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.java b/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.javaindex 4db6a42288e..c582eff4c08 100644--- a/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.java+++ b/solr/core/src/java/org/apache/solr/util/StartupLoggingUtils.java@@ -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";+ }}diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 2f2f9cc9c9c..c35004ec395 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -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 {@BeforeClasspublic 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);}/**