[PATCH] Rely on log4j's default initialization procedure

Wald Commits scm-commit at wald.intevation.org
Fri Feb 25 17:20:28 CET 2022


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1645798504 -3600
#      Fri Feb 25 15:15:04 2022 +0100
# Branch 3.2.x
# Node ID 7261c948425cb4fb6210f1103eacc94a41e4f157
# Parent  ddbb7256246f60ece0871cfbafa0a168b196963f
Rely on log4j's default initialization procedure

This should make upgrading to Log4j 2.x easier.
In passing, use latest Log4j 1.

diff -r ddbb7256246f -r 7261c948425c README
--- a/README	Mon Mar 22 12:41:23 2021 +0100
+++ b/README	Fri Feb 25 15:15:04 2022 +0100
@@ -1,18 +1,8 @@
-============
-DEPENDENCIES
-============
-
-- JUnit 3.8.1
-- Log4j 1.2.14
-- Restlet 2.0-SNAPSHOT
-- Restlet-XML 2.0-SNAPSHOT
-
-
 ============================
 COMPILATION AND INSTALLATION
 ============================
 
-This project is based on maven2. To compile/install this client, just do:
+This project is based on Maven. To compile/install this client, just do:
 
     mvn compile package
 
@@ -41,7 +31,7 @@
 RUNNING THE CLIENT
 ==================
 
-There is a bash script in the ``contrib`` directory. This might be used to
+There is a bash script that might be used to
 start the console based client. Note, that you need the jars of the depending
 libraries in the ``target`` directory.
 
diff -r ddbb7256246f -r 7261c948425c bin/run.sh
--- a/bin/run.sh	Mon Mar 22 12:41:23 2021 +0100
+++ b/bin/run.sh	Fri Feb 25 15:15:04 2022 +0100
@@ -14,5 +14,6 @@
      -Djava.io.tmpdir="$DIR/cache" \
      -Dconfig.dir="$DIR/conf" \
      -Dconfig.file="demo-config.conf" \
-     de.intevation.bsh.consoleclient.ConsoleClient \
+     -Dlog4j.configuration="file://$DIR/conf/log4j.properties" \
+     org.dive4elements.artifacts.httpclient.ConsoleClient \
      2>&1 > /dev/null
diff -r ddbb7256246f -r 7261c948425c pom.xml
--- a/pom.xml	Mon Mar 22 12:41:23 2021 +0100
+++ b/pom.xml	Fri Feb 25 15:15:04 2022 +0100
@@ -46,7 +46,7 @@
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
-      <version>1.2.14</version>
+      <version>1.2.17</version>
     </dependency>
     <dependency>
       <groupId>org.restlet.jse</groupId>
diff -r ddbb7256246f -r 7261c948425c src/main/java/org/dive4elements/artifacts/httpclient/ConsoleClient.java
--- a/src/main/java/org/dive4elements/artifacts/httpclient/ConsoleClient.java	Mon Mar 22 12:41:23 2021 +0100
+++ b/src/main/java/org/dive4elements/artifacts/httpclient/ConsoleClient.java	Fri Feb 25 15:15:04 2022 +0100
@@ -13,8 +13,6 @@
 import java.io.FileOutputStream;
 import java.io.OutputStream;
 
-import java.net.MalformedURLException;
-
 import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -28,7 +26,6 @@
 import org.w3c.dom.NodeList;
 
 import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
 
 import org.dive4elements.artifacts.httpclient.http.HttpClient;
 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
@@ -48,13 +45,6 @@
 public class ConsoleClient
 {
     /**
-     * The logging is done via Log4j. To configure the logging
-     * a file 'log4j.properties' is search in the configuration directory.
-     */
-    public static final String LOG4J_PROPERTIES = "log4j.properties";
-
-
-    /**
      * The path of the configuration directory.
      */
     public static final String CONFIG_PATH = System.getProperty("config.dir",
@@ -69,32 +59,7 @@
     /**
      * The logger used in this class.
      */
-    private static Logger logger;
-
-
-    static {
-        configureLogging();
-
-        logger = Logger.getLogger(ConsoleClient.class);
-    }
-
-
-    /**
-     * Trys to load the Log4j configuration from ${config.dir}/log4j.properties.
-     */
-    public static final void configureLogging() {
-        File configDir = new File(CONFIG_PATH);
-        File propFile  = new File(configDir, LOG4J_PROPERTIES);
-
-        if (propFile.isFile() && propFile.canRead()) {
-            try {
-                PropertyConfigurator.configure(propFile.toURI().toURL());
-            }
-            catch (MalformedURLException mue) {
-                mue.printStackTrace(System.err);
-            }
-        }
-    }
+    private static Logger logger = Logger.getLogger(ConsoleClient.class);
 
 
     public static final Configuration readConfiguration() {


More information about the Dive4Elements-commits mailing list