This is an automated email from the ASF dual-hosted git repository.

psalagnac pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 0199dd3110e Restore logging level after package tool. (#3432)
0199dd3110e is described below

commit 0199dd3110e34ad48bd2d7b27395285c15d0567c
Author: Pierre Salagnac <[email protected]>
AuthorDate: Tue Jul 22 10:18:48 2025 +0200

    Restore logging level after package tool. (#3432)
    
    This is mostly to fix following tests that run in the same JVM and check 
logger events.
---
 solr/core/src/java/org/apache/solr/cli/PackageTool.java | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cli/PackageTool.java 
b/solr/core/src/java/org/apache/solr/cli/PackageTool.java
index 8dcf316ec55..49779a52828 100644
--- a/solr/core/src/java/org/apache/solr/cli/PackageTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/PackageTool.java
@@ -30,6 +30,7 @@ import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.DeprecatedAttributes;
 import org.apache.commons.cli.Option;
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.lucene.util.SuppressForbidden;
 import org.apache.solr.client.solrj.SolrClient;
@@ -50,12 +51,8 @@ public class PackageTool extends ToolBase {
 
   private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-  @SuppressForbidden(
-      reason = "Need to turn off logging, and SLF4J doesn't seem to provide 
for a way.")
   public PackageTool(ToolRuntime runtime) {
     super(runtime);
-    // Need a logging free, clean output going through to the user.
-    Configurator.setRootLevel(Level.OFF);
   }
 
   @Override
@@ -73,8 +70,14 @@ public class PackageTool extends ToolBase {
       reason =
           "We really need to print the stacktrace here, otherwise "
               + "there shall be little else information to debug problems. 
Other SolrCLI tools "
-              + "don't print stack traces, hence special treatment is needed 
here.")
+              + "don't print stack traces, hence special treatment is needed 
here."
+              + "Need to turn off logging, and SLF4J doesn't seem to provide 
for a way.")
   public void runImpl(CommandLine cli) throws Exception {
+
+    // Need a logging free, clean output going through to the user.
+    Level oldLevel = 
LoggerContext.getContext(false).getRootLogger().getLevel();
+    Configurator.setRootLevel(Level.OFF);
+
     try {
       String solrUrl =
           cli.hasOption("solr-url")
@@ -254,6 +257,9 @@ public class PackageTool extends ToolBase {
       // of brevity. Package tool should surely print full stacktraces!
       ex.printStackTrace();
       throw ex;
+    } finally {
+      // Restore the old logging level
+      Configurator.setRootLevel(oldLevel);
     }
   }
 

Reply via email to