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:48 UTC
(commons-logging) branch master updated (35427e2 -> afb2950)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-logging.git
from 35427e2 Disable Lumberjack and Log4j 1.x and document it (#182)
new 942b1c3 Sort members
new 5c371bc Organize imports
new afb2950 Remove trailing whitespace
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/commons/logging/LogFactory.java | 98 +++++++++++-----------
.../java/org/apache/commons/logging/LogSource.java | 6 +-
.../logging/impl/Jdk13LumberjackLogger.java | 6 +-
.../apache/commons/logging/impl/Jdk14Logger.java | 2 +-
.../apache/commons/logging/impl/Log4JLogger.java | 60 ++++++-------
.../commons/logging/impl/LogFactoryImpl.java | 12 +--
.../apache/commons/logging/impl/LogKitLogger.java | 8 +-
.../org/apache/commons/logging/impl/SimpleLog.java | 16 ++--
.../log4j12/ApiClasspathStandardTestCase.java | 1 -
9 files changed, 104 insertions(+), 105 deletions(-)
(commons-logging) 01/03: Sort members
Posted by gg...@apache.org.
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;
- }
-
}
(commons-logging) 02/03: Organize imports
Posted by gg...@apache.org.
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 5c371bcbbdfb376862c8ed28f1ecbfb99d2a8ae5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 25 11:08:11 2023 -0500
Organize imports
---
.../commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/test/java/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java b/src/test/java/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java
index 7790c28..c825609 100644
--- a/src/test/java/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java
+++ b/src/test/java/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java
@@ -20,7 +20,6 @@ package org.apache.commons.logging.log4j.log4j12;
import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.Log4JLogger;
-import org.apache.commons.logging.impl.Log4jApiLogFactory;
import org.apache.commons.logging.impl.LogFactoryImpl;
import junit.framework.Test;
(commons-logging) 03/03: Remove trailing whitespace
Posted by gg...@apache.org.
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 afb295013dfacc587b0d1aa74bdae80d5bfad082
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 25 11:09:13 2023 -0500
Remove trailing whitespace
---
src/main/java/org/apache/commons/logging/LogFactory.java | 14 +++++++-------
src/main/java/org/apache/commons/logging/LogSource.java | 6 +++---
.../commons/logging/impl/Jdk13LumberjackLogger.java | 6 +++---
.../org/apache/commons/logging/impl/Jdk14Logger.java | 2 +-
.../org/apache/commons/logging/impl/Log4JLogger.java | 2 +-
.../org/apache/commons/logging/impl/LogFactoryImpl.java | 12 ++++++------
.../org/apache/commons/logging/impl/LogKitLogger.java | 8 ++++----
.../java/org/apache/commons/logging/impl/SimpleLog.java | 16 ++++++++--------
8 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/src/main/java/org/apache/commons/logging/LogFactory.java b/src/main/java/org/apache/commons/logging/LogFactory.java
index 6bc87c2..88418d7 100644
--- a/src/main/java/org/apache/commons/logging/LogFactory.java
+++ b/src/main/java/org/apache/commons/logging/LogFactory.java
@@ -69,7 +69,7 @@ public abstract class LogFactory {
// lib and JCL have the necessary permissions even when the untrusted
// caller does not. That's a pretty hard route to exploit though.
-
+
/**
* The name ({@code priority}) of the key in the config file used to
* specify the priority of that particular config file. The associated value
@@ -203,14 +203,14 @@ public abstract class LogFactory {
*/
private static final int MAX_BROKEN_SERVICES = 3;
-
+
/**
* The previously constructed {@code LogFactory} instances, keyed by
* the {@code ClassLoader} with which it was created.
*/
protected static Hashtable<ClassLoader, LogFactory> factories;
-
+
/**
* Previously constructed {@code LogFactory} instance as in the
* {@code factories} map, but for the case where
@@ -530,7 +530,7 @@ public abstract class LogFactory {
return classLoader;
}
-
+
/**
* Check cached factories (keyed by contextClassLoader)
*
@@ -688,7 +688,7 @@ public abstract class LogFactory {
return props;
}
-
+
/**
* Returns the current context classloader.
* <p>
@@ -1075,7 +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
@@ -1592,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.
diff --git a/src/main/java/org/apache/commons/logging/LogSource.java b/src/main/java/org/apache/commons/logging/LogSource.java
index 7239cc5..b58f2ff 100644
--- a/src/main/java/org/apache/commons/logging/LogSource.java
+++ b/src/main/java/org/apache/commons/logging/LogSource.java
@@ -71,7 +71,7 @@ public class LogSource {
* An empty immutable {@code String} array.
*/
private static final String[] EMPTY_STRING_ARRAY = {};
-
+
static {
// Is Log4J Available?
@@ -127,7 +127,7 @@ public class LogSource {
}
}
-
+
/**
* Gets a {@code Log} instance by class.
*
@@ -137,7 +137,7 @@ public class LogSource {
static public Log getInstance(final Class<?> clazz) {
return getInstance(clazz.getName());
}
-
+
/**
* Gets a {@code Log} instance by class name.
*
diff --git a/src/main/java/org/apache/commons/logging/impl/Jdk13LumberjackLogger.java b/src/main/java/org/apache/commons/logging/impl/Jdk13LumberjackLogger.java
index 317e111..9dc1e47 100644
--- a/src/main/java/org/apache/commons/logging/impl/Jdk13LumberjackLogger.java
+++ b/src/main/java/org/apache/commons/logging/impl/Jdk13LumberjackLogger.java
@@ -41,7 +41,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = -8649807923527610591L;
-
+
/**
* This member variable simply ensures that any attempt to initialize
* this class in a pre-1.4 JVM will result in an ExceptionInInitializerError.
@@ -69,7 +69,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
/** Class and method found flag. */
private boolean classAndMethodFound;
-
+
/**
* Constructs a named instance of this Logger.
*
@@ -80,7 +80,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
logger = getLogger();
}
-
+
/**
* Logs a message with {@code java.util.logging.Level.FINE}.
*
diff --git a/src/main/java/org/apache/commons/logging/impl/Jdk14Logger.java b/src/main/java/org/apache/commons/logging/impl/Jdk14Logger.java
index f866ce1..ea42c18 100644
--- a/src/main/java/org/apache/commons/logging/impl/Jdk14Logger.java
+++ b/src/main/java/org/apache/commons/logging/impl/Jdk14Logger.java
@@ -41,7 +41,7 @@ public class Jdk14Logger implements Log, Serializable {
*/
protected static final Level dummyLevel = Level.FINE;
-
+
/**
* The underlying Logger implementation we are using.
*/
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 b93c0d9..11245b9 100644
--- a/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java
+++ b/src/main/java/org/apache/commons/logging/impl/Log4JLogger.java
@@ -63,7 +63,7 @@ public class Log4JLogger implements Log, Serializable {
// 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.
+ // discovery will continue.
static {
if (!Priority.class.isAssignableFrom(Level.class)) {
// nope, this is log4j 1.3, so force an ExceptionInInitializerError
diff --git a/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java b/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
index 8edaa0b..488e9ac 100644
--- a/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
+++ b/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
@@ -80,14 +80,14 @@ public class LogFactoryImpl extends LogFactory {
*/
private static final String[] EMPTY_STRING_ARRAY = {};
-
+
/**
* The name ({@code org.apache.commons.logging.Log}) of the system
* property identifying our {@link Log} implementation class.
*/
public static final String LOG_PROPERTY = "org.apache.commons.logging.Log";
-
+
/**
* The deprecated system property used for backwards compatibility with
* old versions of JCL.
@@ -165,7 +165,7 @@ public class LogFactoryImpl extends LogFactory {
return LogFactory.getClassLoader(clazz);
}
-
+
/**
* Gets the context ClassLoader.
* This method is a workaround for a java 1.2 compiler bug.
@@ -273,7 +273,7 @@ public class LogFactoryImpl extends LogFactory {
*/
protected Class[] logConstructorSignature = { String.class };
-
+
/**
* The one-argument {@code setLogFactory} method of the selected
* {@link org.apache.commons.logging.Log} method, if it exists.
@@ -488,7 +488,7 @@ public class LogFactoryImpl extends LogFactory {
//
// These methods only defined as workarounds for a java 1.2 bug;
// theoretically none of these are needed.
-
+
/**
* Attempts to create a Log instance for the given category name.
* Follows the discovery process described in the class Javadoc.
@@ -654,7 +654,7 @@ public class LogFactoryImpl extends LogFactory {
return attributes.get(name);
}
-
+
/**
* Return an array containing the names of all currently defined
* configuration attributes. If there are no such attributes, a zero
diff --git a/src/main/java/org/apache/commons/logging/impl/LogKitLogger.java b/src/main/java/org/apache/commons/logging/impl/LogKitLogger.java
index f429794..d2112d0 100644
--- a/src/main/java/org/apache/commons/logging/impl/LogKitLogger.java
+++ b/src/main/java/org/apache/commons/logging/impl/LogKitLogger.java
@@ -40,14 +40,14 @@ public class LogKitLogger implements Log, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = 3768538055836059519L;
-
+
/** Logging goes to this {@code LogKit} logger */
protected transient volatile Logger logger;
/** Name of this logger */
protected String name;
-
+
/**
* Constructs {@code LogKitLogger} which wraps the {@code LogKit}
* logger with given name.
@@ -59,7 +59,7 @@ public class LogKitLogger implements Log, Serializable {
this.logger = getLogger();
}
-
+
/**
* Logs a message with {@code org.apache.log.Priority.DEBUG}.
*
@@ -73,7 +73,7 @@ public class LogKitLogger implements Log, Serializable {
}
}
-
+
/**
* Logs a message with {@code org.apache.log.Priority.DEBUG}.
*
diff --git a/src/main/java/org/apache/commons/logging/impl/SimpleLog.java b/src/main/java/org/apache/commons/logging/impl/SimpleLog.java
index 78ae890..b583977 100644
--- a/src/main/java/org/apache/commons/logging/impl/SimpleLog.java
+++ b/src/main/java/org/apache/commons/logging/impl/SimpleLog.java
@@ -74,7 +74,7 @@ public class SimpleLog implements Log, Serializable {
/** Serializable version identifier. */
private static final long serialVersionUID = 136942970684951178L;
-
+
/** All system properties used by {@code SimpleLog} start with this */
static protected final String systemPrefix = "org.apache.commons.logging.simplelog.";
@@ -110,7 +110,7 @@ public class SimpleLog implements Log, Serializable {
*/
static protected DateFormat dateFormatter;
-
+
/** "Trace" level logging. */
public static final int LOG_LEVEL_TRACE = 1;
/** "Debug" level logging. */
@@ -130,7 +130,7 @@ public class SimpleLog implements Log, Serializable {
/** Enable no logging levels */
public static final int LOG_LEVEL_OFF = LOG_LEVEL_FATAL + 1;
-
+
// Initialize class attributes.
// Load properties file, if found.
// Override with system properties.
@@ -242,7 +242,7 @@ public class SimpleLog implements Log, Serializable {
});
}
-
+
private static String getStringProperty(final String name) {
String prop = null;
try {
@@ -259,11 +259,11 @@ public class SimpleLog implements Log, Serializable {
/** The name of this simple log instance */
protected volatile String logName;
-
+
/** The current log level */
protected volatile int currentLogLevel;
-
+
/** The short name of this simple log instance */
private volatile String shortLogName;
@@ -312,7 +312,7 @@ public class SimpleLog implements Log, Serializable {
}
}
-
+
/**
* Logs a message with
* {@code org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG}.
@@ -369,7 +369,7 @@ public class SimpleLog implements Log, Serializable {
}
}
-
+
/**
* Log a message with {@code org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL}.
*