You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/11/25 16:09:49 UTC

(commons-logging) 01/03: Sort members

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-logging.git

commit 942b1c37afdb4463d736353d49949607660c8c47
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 25 11:07:56 2023 -0500

    Sort members
---
 .../org/apache/commons/logging/LogFactory.java     | 94 +++++++++++-----------
 .../apache/commons/logging/impl/Log4JLogger.java   | 60 +++++++-------
 2 files changed, 77 insertions(+), 77 deletions(-)

diff --git a/src/main/java/org/apache/commons/logging/LogFactory.java b/src/main/java/org/apache/commons/logging/LogFactory.java
index 34475d6..6bc87c2 100644
--- a/src/main/java/org/apache/commons/logging/LogFactory.java
+++ b/src/main/java/org/apache/commons/logging/LogFactory.java
@@ -229,6 +229,39 @@ public abstract class LogFactory {
     @Deprecated
     protected static volatile LogFactory nullClassLoaderFactory;
 
+    static {
+        // note: it's safe to call methods before initDiagnostics (though
+        // diagnostic output gets discarded).
+        final ClassLoader thisClassLoader = getClassLoader(LogFactory.class);
+        thisClassLoaderRef = new WeakReference<>(thisClassLoader);
+        // In order to avoid confusion where multiple instances of JCL are
+        // being used via different class loaders within the same app, we
+        // ensure each logged message has a prefix of form
+        // [LogFactory from classloader OID]
+        //
+        // Note that this prefix should be kept consistent with that
+        // in LogFactoryImpl. However here we don't need to output info
+        // about the actual *instance* of LogFactory, as all methods that
+        // output diagnostics from this class are static.
+        String classLoaderName;
+        try {
+            if (thisClassLoader == null) {
+                classLoaderName = "BOOTLOADER";
+            } else {
+                classLoaderName = objectId(thisClassLoader);
+            }
+        } catch (final SecurityException e) {
+            classLoaderName = "UNKNOWN";
+        }
+        diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
+        DIAGNOSTICS_STREAM = initDiagnostics();
+        logClassLoaderEnvironment(LogFactory.class);
+        factories = createFactoryStore();
+        if (isDiagnosticsEnabled()) {
+            logDiagnostic("BOOTSTRAP COMPLETED");
+        }
+    }
+
     /**
      * Remember this factory, so later calls to LogFactory.getCachedFactory
      * can return the previously created object (together with all its
@@ -497,6 +530,7 @@ public abstract class LogFactory {
         return classLoader;
     }
 
+    
     /**
      * Check cached factories (keyed by contextClassLoader)
      *
@@ -522,7 +556,6 @@ public abstract class LogFactory {
         return factories.get(contextClassLoader);
     }
 
-    
     /**
      * Safely get access to the classloader for the specified class.
      * <p>
@@ -655,6 +688,7 @@ public abstract class LogFactory {
         return props;
     }
 
+    
     /**
      * Returns the current context classloader.
      * <p>
@@ -676,7 +710,6 @@ public abstract class LogFactory {
         return directGetContextClassLoader();
     }
 
-    
     /**
      * Calls LogFactory.directGetContextClassLoader under the control of an
      * AccessController class. This means that java code running under a
@@ -1042,6 +1075,7 @@ public abstract class LogFactory {
         });
     }
 
+    
     /**
      * Read the specified system property, using an AccessController so that
      * the property can be read if JCL has been granted the appropriate
@@ -1056,7 +1090,6 @@ public abstract class LogFactory {
         return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(key, def));
     }
 
-    
     /**
      * Checks whether the supplied Throwable is one that needs to be
      * re-thrown and ignores all others.
@@ -1559,7 +1592,7 @@ public abstract class LogFactory {
      * class loader would prevent garbage collection.
      */
     public abstract void release();
-
+    
     /**
      * Remove any configuration attribute associated with the specified name.
      * If there is no such attribute, no action is taken.
@@ -1567,17 +1600,6 @@ public abstract class LogFactory {
      * @param name Name of the attribute to remove
      */
     public abstract void removeAttribute(String name);
-    
-    /**
-     * Sets the configuration attribute with the specified name.  Calling
-     * this with a {@code null} value is equivalent to calling
-     * {@code removeAttribute(name)}.
-     *
-     * @param name Name of the attribute to set
-     * @param value Value of the attribute to set, or {@code null}
-     *  to remove any setting for this attribute
-     */
-    public abstract void setAttribute(String name, Object value);
 
     //
     // We can't do this in the class constructor, as there are many
@@ -1595,37 +1617,15 @@ public abstract class LogFactory {
     // So the wisest thing to do is just to place this code at the very end
     // of the class file.
 
-    static {
-        // note: it's safe to call methods before initDiagnostics (though
-        // diagnostic output gets discarded).
-        final ClassLoader thisClassLoader = getClassLoader(LogFactory.class);
-        thisClassLoaderRef = new WeakReference<>(thisClassLoader);
-        // In order to avoid confusion where multiple instances of JCL are
-        // being used via different class loaders within the same app, we
-        // ensure each logged message has a prefix of form
-        // [LogFactory from classloader OID]
-        //
-        // Note that this prefix should be kept consistent with that
-        // in LogFactoryImpl. However here we don't need to output info
-        // about the actual *instance* of LogFactory, as all methods that
-        // output diagnostics from this class are static.
-        String classLoaderName;
-        try {
-            if (thisClassLoader == null) {
-                classLoaderName = "BOOTLOADER";
-            } else {
-                classLoaderName = objectId(thisClassLoader);
-            }
-        } catch (final SecurityException e) {
-            classLoaderName = "UNKNOWN";
-        }
-        diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
-        DIAGNOSTICS_STREAM = initDiagnostics();
-        logClassLoaderEnvironment(LogFactory.class);
-        factories = createFactoryStore();
-        if (isDiagnosticsEnabled()) {
-            logDiagnostic("BOOTSTRAP COMPLETED");
-        }
-    }
+    /**
+     * Sets the configuration attribute with the specified name.  Calling
+     * this with a {@code null} value is equivalent to calling
+     * {@code removeAttribute(name)}.
+     *
+     * @param name Name of the attribute to set
+     * @param value Value of the attribute to set, or {@code null}
+     *  to remove any setting for this attribute
+     */
+    public abstract void setAttribute(String name, Object value);
 
 }
diff --git a/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java b/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java
index 014f008..b93c0d9 100644
--- a/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java
+++ b/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java
@@ -54,6 +54,36 @@ public class Log4JLogger implements Log, Serializable {
 
     private static final Priority traceLevel;
 
+    //
+    // Note that this must come after the static variable declarations
+    // otherwise initializer expressions associated with those variables
+    // will override any settings done here.
+    //
+    // Verify that log4j is available, and that it is version 1.2.
+    // If an ExceptionInInitializerError is generated, then LogFactoryImpl
+    // will treat that as meaning that the appropriate underlying logging
+    // library is just not present - if discovery is in progress then
+    // discovery will continue.    
+    static {
+        if (!Priority.class.isAssignableFrom(Level.class)) {
+            // nope, this is log4j 1.3, so force an ExceptionInInitializerError
+            throw new InstantiationError("Log4J 1.2 not available");
+        }
+
+        // Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
+        // versions do not. If TRACE is not available, then we have to map
+        // calls to Log.trace(...) onto the DEBUG level.
+
+        Priority _traceLevel;
+        try {
+            _traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
+        } catch (final Exception ex) {
+            // ok, trace not available
+            _traceLevel = Level.DEBUG;
+        }
+        traceLevel = _traceLevel;
+    }
+
     /** Log to this logger */
     private transient volatile Logger logger;
 
@@ -301,34 +331,4 @@ public class Log4JLogger implements Log, Serializable {
         getLogger().log(FQCN, Level.WARN, message, t);
     }
 
-    //
-    // Note that this must come after the static variable declarations
-    // otherwise initializer expressions associated with those variables
-    // will override any settings done here.
-    //
-    // Verify that log4j is available, and that it is version 1.2.
-    // If an ExceptionInInitializerError is generated, then LogFactoryImpl
-    // will treat that as meaning that the appropriate underlying logging
-    // library is just not present - if discovery is in progress then
-    // discovery will continue.    
-    static {
-        if (!Priority.class.isAssignableFrom(Level.class)) {
-            // nope, this is log4j 1.3, so force an ExceptionInInitializerError
-            throw new InstantiationError("Log4J 1.2 not available");
-        }
-
-        // Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
-        // versions do not. If TRACE is not available, then we have to map
-        // calls to Log.trace(...) onto the DEBUG level.
-
-        Priority _traceLevel;
-        try {
-            _traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
-        } catch (final Exception ex) {
-            // ok, trace not available
-            _traceLevel = Level.DEBUG;
-        }
-        traceLevel = _traceLevel;
-    }
-
 }