JAL-3933 configure root logger console appender to stderr (2.11.2 version)
authorJim Procter <j.procter@dundee.ac.uk>
Wed, 15 Dec 2021 10:36:18 +0000 (10:36 +0000)
committerJim Procter <j.procter@dundee.ac.uk>
Wed, 15 Dec 2021 10:41:04 +0000 (10:41 +0000)
src/jalview/bin/Cache.java

index c93d611..aa9c030 100755 (executable)
@@ -51,6 +51,12 @@ import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.builders.appender.ConsoleAppenderBuilder;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
+import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
 
 import jalview.datamodel.PDBEntry;
 import jalview.gui.Preferences;
@@ -328,14 +334,11 @@ public class Cache
     }
     try
     {
-      // TODO: redirect stdout and stderr here in order to grab the output of
-      // the log
-
-      ConsoleAppender ap = new ConsoleAppender();
-      ap.setLayout(new SimpleLayout());
-      //ap.setTarget("System.err");
-      ap.setName("JalviewLogger");
-      org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
+      // configure the root logger to stderr
+      ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
+      AppenderComponentBuilder consoleApp = builder.newAppender("stderr", "Console");
+      builder.add(consoleApp);
+      Configurator.initialize(builder.build());
       // log output
       Logger laxis = Logger.getLogger("org.apache.axis");
       Logger lcastor = Logger.getLogger("org.exolab.castor");