JAL-3933 configure root logger console appender to stderr
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:36:18 +0000 (10:36 +0000)
src/jalview/bin/Cache.java

index afabf02..6266b71 100755 (executable)
@@ -47,6 +47,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.UserDefinedColours;
@@ -303,12 +309,10 @@ public class Cache
     {
       // 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
+      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");