From d960f15294c451bda338e4d9998e8d009970f380 Mon Sep 17 00:00:00 2001 From: Yuan Liao Date: Fri, 18 Feb 2022 12:47:20 -0800 Subject: [PATCH] Migrate from Log4j 1.2 to log4j-1.2-api bridge from Log4j 2 Signed-off-by: Yuan Liao --- org/gudy/azureus2/ui/common/Main.java | 7 +++--- .../azureus2/ui/console/ConsoleInput.java | 8 +++--- .../azureus2/ui/console/commands/Log.java | 25 ++++++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/org/gudy/azureus2/ui/common/Main.java b/org/gudy/azureus2/ui/common/Main.java index 8c533fb..f93e685 100644 --- a/org/gudy/azureus2/ui/common/Main.java +++ b/org/gudy/azureus2/ui/common/Main.java @@ -43,7 +43,8 @@ import org.apache.log4j.Appender; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; -import org.apache.log4j.varia.DenyAllFilter; +import org.apache.log4j.bridge.FilterWrapper; +import org.apache.logging.log4j.core.filter.DenyAllFilter; import com.aelitis.azureus.core.*; import com.aelitis.azureus.core.impl.AzureusCoreSingleInstanceClient; @@ -113,9 +114,9 @@ public class Main { public static void initRootLogger() { if (Logger.getRootLogger().getAppender("ConsoleAppender")==null) { Appender app; - app = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)); + app = new ConsoleAppender(); app.setName("ConsoleAppender"); - app.addFilter( new DenyAllFilter() ); //'log off' by default + app.addFilter( new FilterWrapper(DenyAllFilter.newBuilder().build()) ); //'log off' by default Logger.getRootLogger().addAppender(app); } } diff --git a/org/gudy/azureus2/ui/console/ConsoleInput.java b/org/gudy/azureus2/ui/console/ConsoleInput.java index d660bbb..0559f72 100644 --- a/org/gudy/azureus2/ui/console/ConsoleInput.java +++ b/org/gudy/azureus2/ui/console/ConsoleInput.java @@ -34,8 +34,8 @@ import java.util.Vector; import org.apache.log4j.Appender; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.varia.DenyAllFilter; +import org.apache.log4j.bridge.FilterWrapper; +import org.apache.logging.log4j.core.filter.DenyAllFilter; import org.gudy.azureus2.core3.config.COConfigurationManager; import org.gudy.azureus2.core3.download.DownloadManager; import org.gudy.azureus2.core3.download.DownloadManagerState; @@ -157,9 +157,9 @@ public class ConsoleInput extends Thread { if (Logger.getRootLogger().getAppender("ConsoleAppender")==null) { Appender app; - app = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)); + app = new ConsoleAppender(); app.setName("ConsoleAppender"); - app.addFilter( new DenyAllFilter() ); //'log off' by default + app.addFilter( new FilterWrapper(DenyAllFilter.newBuilder().build()) ); //'log off' by default Logger.getRootLogger().addAppender(app); } diff --git a/org/gudy/azureus2/ui/console/commands/Log.java b/org/gudy/azureus2/ui/console/commands/Log.java index 43f66d5..8e9b222 100644 --- a/org/gudy/azureus2/ui/console/commands/Log.java +++ b/org/gudy/azureus2/ui/console/commands/Log.java @@ -18,10 +18,13 @@ import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.log4j.Appender; import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.FileAppender; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; -import org.apache.log4j.varia.DenyAllFilter; +import org.apache.log4j.bridge.AppenderWrapper; +import org.apache.log4j.bridge.FilterWrapper; +import org.apache.log4j.bridge.LayoutAdapter; +import org.apache.logging.log4j.core.appender.FileAppender; +import org.apache.logging.log4j.core.filter.DenyAllFilter; import org.gudy.azureus2.plugins.PluginInterface; import org.gudy.azureus2.plugins.logging.LoggerChannel; import org.gudy.azureus2.plugins.logging.LoggerChannelListener; @@ -54,7 +57,7 @@ public class Log extends OptionsConsoleCommand { String subcommand = (String) args.get(0); if ("off".equalsIgnoreCase(subcommand) ) { if ( args.size() == 1 ){ - con.addFilter(new DenyAllFilter()); + con.addFilter(new FilterWrapper(DenyAllFilter.newBuilder().build())); ci.out.println("> Console logging off"); }else{ @@ -81,25 +84,23 @@ public class Log extends OptionsConsoleCommand { { // send log output to a file String filename = commandLine.getOptionValue('f'); - - try - { - Appender newAppender = new FileAppender(new PatternLayout("%d{ISO8601} %c{1}-%p: %m%n"), filename, true); + + Appender newAppender = new AppenderWrapper(FileAppender.newBuilder() + .setLayout(new LayoutAdapter(new PatternLayout("%d{ISO8601} %c{1}-%p: %m%n"))) + .withFileName(filename) + .withAppend(true) + .build()); newAppender.setName("ConsoleAppender"); Logger.getRootLogger().removeAppender(con); Logger.getRootLogger().addAppender(newAppender); ci.out.println("> Logging to filename: " + filename); - } catch (IOException e) - { - ci.out.println("> Unable to log to file: " + filename + ": " + e); - } } else { if( ! (con instanceof ConsoleAppender) ) { Logger.getRootLogger().removeAppender(con); - con = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)); + con = new ConsoleAppender(); con.setName("ConsoleAppender"); Logger.getRootLogger().addAppender(con); } -- 2.34.1