This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 6d27f275d4 Code clean-up - formatting. No functional change. 6d27f275d4 is described below commit 6d27f275d4f22ea7bdc8508d1fa76e267c3f2047 Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Mar 28 19:28:04 2025 +0000 Code clean-up - formatting. No functional change. --- java/org/apache/juli/logging/DirectJDKLog.java | 27 ++- java/org/apache/juli/logging/Log.java | 194 ++++++++++++--------- .../juli/logging/LogConfigurationException.java | 12 +- java/org/apache/juli/logging/LogFactory.java | 171 ++++++++---------- 4 files changed, 204 insertions(+), 200 deletions(-) diff --git a/java/org/apache/juli/logging/DirectJDKLog.java b/java/org/apache/juli/logging/DirectJDKLog.java index ba47c0cb98..70226d1b3c 100644 --- a/java/org/apache/juli/logging/DirectJDKLog.java +++ b/java/org/apache/juli/logging/DirectJDKLog.java @@ -30,23 +30,23 @@ class DirectJDKLog implements Log { public final Logger logger; // Alternate config reader and console format - private static final String SIMPLE_FMT="java.util.logging.SimpleFormatter"; - private static final String FORMATTER="org.apache.juli.formatter"; + private static final String SIMPLE_FMT = "java.util.logging.SimpleFormatter"; + private static final String FORMATTER = "org.apache.juli.formatter"; static { - if (System.getProperty("java.util.logging.config.class") == null && + if (System.getProperty("java.util.logging.config.class") == null && System.getProperty("java.util.logging.config.file") == null) { // default configuration - it sucks. Let's override at least the // formatter for the console try { - Formatter fmt= (Formatter) Class.forName(System.getProperty( - FORMATTER, SIMPLE_FMT)).getConstructor().newInstance(); + Formatter fmt = (Formatter) Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).getConstructor() + .newInstance(); // it is also possible that the user modified jre/lib/logging.properties - // but that's really stupid in most cases - Logger root=Logger.getLogger(""); + Logger root = Logger.getLogger(""); for (Handler handler : root.getHandlers()) { // I only care about console - that's what's used in default config anyway - if (handler instanceof ConsoleHandler) { + if (handler instanceof ConsoleHandler) { handler.setFormatter(fmt); } } @@ -57,8 +57,8 @@ class DirectJDKLog implements Log { } } - DirectJDKLog(String name ) { - logger=Logger.getLogger(name); + DirectJDKLog(String name) { + logger = Logger.getLogger(name); } @Override @@ -154,17 +154,17 @@ class DirectJDKLog implements Log { private void log(Level level, String msg, Throwable ex) { if (logger.isLoggable(level)) { // Hack (?) to get the stack trace. - Throwable dummyException=new Throwable(); + Throwable dummyException = new Throwable(); StackTraceElement[] locations = dummyException.getStackTrace(); // Caller will be the third element String cname = "unknown"; String method = "unknown"; - if (locations != null && locations.length >2) { + if (locations != null && locations.length > 2) { StackTraceElement caller = locations[2]; cname = caller.getClassName(); method = caller.getMethodName(); } - if (ex==null) { + if (ex == null) { logger.logp(level, cname, method, msg); } else { logger.logp(level, cname, method, msg, ex); @@ -173,8 +173,7 @@ class DirectJDKLog implements Log { } static Log getInstance(String name) { - return new DirectJDKLog( name ); + return new DirectJDKLog(name); } } - diff --git a/java/org/apache/juli/logging/Log.java b/java/org/apache/juli/logging/Log.java index 270eeee36e..2a79770714 100644 --- a/java/org/apache/juli/logging/Log.java +++ b/java/org/apache/juli/logging/Log.java @@ -17,12 +17,14 @@ package org.apache.juli.logging; /** - * <p>A simple logging interface abstracting logging APIs. In order to be - * instantiated successfully by {@link LogFactory}, classes that implement - * this interface must have a constructor that takes a single String - * parameter representing the "name" of this Log.</p> - * - * <p> The six logging levels used by <code>Log</code> are (in order):</p> + * <p> + * A simple logging interface abstracting logging APIs. In order to be instantiated successfully by {@link LogFactory}, + * classes that implement this interface must have a constructor that takes a single String parameter representing the + * "name" of this Log. + * </p> + * <p> + * The six logging levels used by <code>Log</code> are (in order): + * </p> * <ol> * <li>trace (the least serious)</li> * <li>debug</li> @@ -31,28 +33,26 @@ package org.apache.juli.logging; * <li>error</li> * <li>fatal (the most serious)</li> * </ol> - * <p>The mapping of these log levels to the concepts used by the underlying - * logging system is implementation dependent. - * The implementation should ensure, though, that this ordering behaves - * as expected.</p> - * - * <p>Performance is often a logging concern. - * By examining the appropriate property, - * a component can avoid expensive operations (producing information - * to be logged).</p> - * - * <p> For example, - * <code> + * <p> + * The mapping of these log levels to the concepts used by the underlying logging system is implementation dependent. + * The implementation should ensure, though, that this ordering behaves as expected. + * </p> + * <p> + * Performance is often a logging concern. By examining the appropriate property, a component can avoid expensive + * operations (producing information to be logged). + * </p> + * <p> + * For example, <code> * if (log.isDebugEnabled()) { * ... do something expensive ... * log.debug(theResult); * } * </code> * </p> - * - * <p>Configuration of the underlying logging system will generally be done - * external to the Logging APIs, through whatever mechanism is supported by - * that system.</p> + * <p> + * Configuration of the underlying logging system will generally be done external to the Logging APIs, through whatever + * mechanism is supported by that system. + * </p> * * @author <a href="mailto:sand...@apache.org">Scott Sanders</a> * @author Rod Waldhoff @@ -64,79 +64,85 @@ public interface Log { /** - * <p> Is debug logging currently enabled? </p> - * - * <p> Call this method to prevent having to perform expensive operations - * (for example, <code>String</code> concatenation) - * when the log level is more than debug. </p> + * <p> + * Is debug logging currently enabled? + * </p> + * <p> + * Call this method to prevent having to perform expensive operations (for example, <code>String</code> + * concatenation) when the log level is more than debug. + * </p> * - * @return <code>true</code> if debug level logging is enabled, otherwise - * <code>false</code> + * @return <code>true</code> if debug level logging is enabled, otherwise <code>false</code> */ boolean isDebugEnabled(); /** - * <p> Is error logging currently enabled? </p> + * <p> + * Is error logging currently enabled? + * </p> + * <p> + * Call this method to prevent having to perform expensive operations (for example, <code>String</code> + * concatenation) when the log level is more than error. + * </p> * - * <p> Call this method to prevent having to perform expensive operations - * (for example, <code>String</code> concatenation) - * when the log level is more than error. </p> - * - * @return <code>true</code> if error level logging is enabled, otherwise - * <code>false</code> + * @return <code>true</code> if error level logging is enabled, otherwise <code>false</code> */ boolean isErrorEnabled(); /** - * <p> Is fatal logging currently enabled? </p> - * - * <p> Call this method to prevent having to perform expensive operations - * (for example, <code>String</code> concatenation) - * when the log level is more than fatal. </p> + * <p> + * Is fatal logging currently enabled? + * </p> + * <p> + * Call this method to prevent having to perform expensive operations (for example, <code>String</code> + * concatenation) when the log level is more than fatal. + * </p> * - * @return <code>true</code> if fatal level logging is enabled, otherwise - * <code>false</code> + * @return <code>true</code> if fatal level logging is enabled, otherwise <code>false</code> */ boolean isFatalEnabled(); /** - * <p> Is info logging currently enabled? </p> + * <p> + * Is info logging currently enabled? + * </p> + * <p> + * Call this method to prevent having to perform expensive operations (for example, <code>String</code> + * concatenation) when the log level is more than info. + * </p> * - * <p> Call this method to prevent having to perform expensive operations - * (for example, <code>String</code> concatenation) - * when the log level is more than info. </p> - * - * @return <code>true</code> if info level logging is enabled, otherwise - * <code>false</code> + * @return <code>true</code> if info level logging is enabled, otherwise <code>false</code> */ boolean isInfoEnabled(); /** - * <p> Is trace logging currently enabled? </p> - * - * <p> Call this method to prevent having to perform expensive operations - * (for example, <code>String</code> concatenation) - * when the log level is more than trace. </p> + * <p> + * Is trace logging currently enabled? + * </p> + * <p> + * Call this method to prevent having to perform expensive operations (for example, <code>String</code> + * concatenation) when the log level is more than trace. + * </p> * - * @return <code>true</code> if trace level logging is enabled, otherwise - * <code>false</code> + * @return <code>true</code> if trace level logging is enabled, otherwise <code>false</code> */ boolean isTraceEnabled(); /** - * <p> Is warn logging currently enabled? </p> - * - * <p> Call this method to prevent having to perform expensive operations - * (for example, <code>String</code> concatenation) - * when the log level is more than warn. </p> + * <p> + * Is warn logging currently enabled? + * </p> + * <p> + * Call this method to prevent having to perform expensive operations (for example, <code>String</code> + * concatenation) when the log level is more than warn. + * </p> * - * @return <code>true</code> if warn level logging is enabled, otherwise - * <code>false</code> + * @return <code>true</code> if warn level logging is enabled, otherwise <code>false</code> */ boolean isWarnEnabled(); @@ -145,7 +151,9 @@ public interface Log { /** - * <p> Log a message with trace log level. </p> + * <p> + * Log a message with trace log level. + * </p> * * @param message log this message */ @@ -153,16 +161,20 @@ public interface Log { /** - * <p> Log an error with trace log level. </p> + * <p> + * Log an error with trace log level. + * </p> * * @param message log this message - * @param t log this cause + * @param t log this cause */ void trace(Object message, Throwable t); /** - * <p> Log a message with debug log level. </p> + * <p> + * Log a message with debug log level. + * </p> * * @param message log this message */ @@ -170,16 +182,20 @@ public interface Log { /** - * <p> Log an error with debug log level. </p> + * <p> + * Log an error with debug log level. + * </p> * * @param message log this message - * @param t log this cause + * @param t log this cause */ void debug(Object message, Throwable t); /** - * <p> Log a message with info log level. </p> + * <p> + * Log a message with info log level. + * </p> * * @param message log this message */ @@ -187,16 +203,20 @@ public interface Log { /** - * <p> Log an error with info log level. </p> + * <p> + * Log an error with info log level. + * </p> * * @param message log this message - * @param t log this cause + * @param t log this cause */ void info(Object message, Throwable t); /** - * <p> Log a message with warn log level. </p> + * <p> + * Log a message with warn log level. + * </p> * * @param message log this message */ @@ -204,16 +224,20 @@ public interface Log { /** - * <p> Log an error with warn log level. </p> + * <p> + * Log an error with warn log level. + * </p> * * @param message log this message - * @param t log this cause + * @param t log this cause */ void warn(Object message, Throwable t); /** - * <p> Log a message with error log level. </p> + * <p> + * Log a message with error log level. + * </p> * * @param message log this message */ @@ -221,16 +245,20 @@ public interface Log { /** - * <p> Log an error with error log level. </p> + * <p> + * Log an error with error log level. + * </p> * * @param message log this message - * @param t log this cause + * @param t log this cause */ void error(Object message, Throwable t); /** - * <p> Log a message with fatal log level. </p> + * <p> + * Log a message with fatal log level. + * </p> * * @param message log this message */ @@ -238,10 +266,12 @@ public interface Log { /** - * <p> Log an error with fatal log level. </p> + * <p> + * Log an error with fatal log level. + * </p> * * @param message log this message - * @param t log this cause + * @param t log this cause */ void fatal(Object message, Throwable t); diff --git a/java/org/apache/juli/logging/LogConfigurationException.java b/java/org/apache/juli/logging/LogConfigurationException.java index 2bc7d9fc88..6059e83483 100644 --- a/java/org/apache/juli/logging/LogConfigurationException.java +++ b/java/org/apache/juli/logging/LogConfigurationException.java @@ -18,9 +18,10 @@ package org.apache.juli.logging; /** - * <p>An exception that is thrown only if a suitable <code>LogFactory</code> - * or <code>Log</code> instance cannot be created by the corresponding - * factory methods.</p> + * <p> + * An exception that is thrown only if a suitable <code>LogFactory</code> or <code>Log</code> instance cannot be created + * by the corresponding factory methods. + * </p> * * @author Craig R. McClanahan */ @@ -49,8 +50,7 @@ public class LogConfigurationException extends RuntimeException { /** - * Construct a new exception with the specified cause and a derived - * detail message. + * Construct a new exception with the specified cause and a derived detail message. * * @param cause The underlying cause */ @@ -63,7 +63,7 @@ public class LogConfigurationException extends RuntimeException { * Construct a new exception with the specified detail message and cause. * * @param message The detail message - * @param cause The underlying cause + * @param cause The underlying cause */ public LogConfigurationException(String message, Throwable cause) { super(message, cause); diff --git a/java/org/apache/juli/logging/LogFactory.java b/java/org/apache/juli/logging/LogFactory.java index 0074ffd796..327f0ec3af 100644 --- a/java/org/apache/juli/logging/LogFactory.java +++ b/java/org/apache/juli/logging/LogFactory.java @@ -24,44 +24,39 @@ import java.util.logging.LogManager; import aQute.bnd.annotation.spi.ServiceConsumer; /** - * This is a modified LogFactory that uses a simple {@link ServiceLoader} based - * discovery mechanism with a default of using JDK based logging. An - * implementation that uses the full Commons Logging discovery mechanism is - * available as part of the Tomcat extras download. + * This is a modified LogFactory that uses a simple {@link ServiceLoader} based discovery mechanism with a default of + * using JDK based logging. An implementation that uses the full Commons Logging discovery mechanism is available as + * part of the Tomcat extras download. * <p> - * Why? It is an attempt to strike a balance between simpler code (no discovery) - * and providing flexibility - particularly for those projects that embed Tomcat - * or some of Tomcat's components - is an alternative logging + * Why? It is an attempt to strike a balance between simpler code (no discovery) and providing flexibility - + * particularly for those projects that embed Tomcat or some of Tomcat's components - is an alternative logging * implementation is desired. * <p> - * Note that this implementation is not just a wrapper around JDK logging (like - * the original commons-logging impl). It adds 2 features - a simpler - * configuration (which is in fact a subset of log4j.properties) and a - * formatter that is less ugly. + * Note that this implementation is not just a wrapper around JDK logging (like the original commons-logging impl). It + * adds 2 features - a simpler configuration (which is in fact a subset of log4j.properties) and a formatter that is + * less ugly. * <p> - * The removal of 'abstract' preserves binary backward compatibility. It is - * possible to preserve the abstract - and introduce another (hardcoded) factory - * - but I see no benefit. + * The removal of 'abstract' preserves binary backward compatibility. It is possible to preserve the abstract - and + * introduce another (hardcoded) factory - but I see no benefit. * <p> - * Since this class is not intended to be extended - all protected methods are - * removed. This can be changed - but again, there is little value in keeping - * dead code. Just take a quick look at the removed code ( and it's complexity). + * Since this class is not intended to be extended - all protected methods are removed. This can be changed - but again, + * there is little value in keeping dead code. Just take a quick look at the removed code ( and it's complexity). * <p> * Original comment: - * <p>Factory for creating {@link Log} instances, with discovery and - * configuration features similar to that employed by standard Java APIs - * such as JAXP.</p> - * - * <p><strong>IMPLEMENTATION NOTE</strong> - This implementation is heavily - * based on the SAXParserFactory and DocumentBuilderFactory implementations - * (corresponding to the JAXP pluggability APIs) found in Apache Xerces.</p> - * + * <p> + * Factory for creating {@link Log} instances, with discovery and configuration features similar to that employed by + * standard Java APIs such as JAXP. + * </p> + * <p> + * <strong>IMPLEMENTATION NOTE</strong> - This implementation is heavily based on the SAXParserFactory and + * DocumentBuilderFactory implementations (corresponding to the JAXP pluggability APIs) found in Apache Xerces. + * </p> * * @author Craig R. McClanahan * @author Costin Manolache * @author Richard A. Sitze */ -@ServiceConsumer(value=Log.class) +@ServiceConsumer(value = Log.class) public class LogFactory { private static final LogFactory singleton = new LogFactory(); @@ -73,33 +68,29 @@ public class LogFactory { */ private LogFactory() { /* - * Work-around known a JRE bug. - * https://bugs.openjdk.java.net/browse/JDK-8194653 + * Work-around known a JRE bug. https://bugs.openjdk.java.net/browse/JDK-8194653 * - * Preload the default file system. No performance impact as we need to - * load the default file system anyway. Just do it earlier to avoid the - * potential deadlock. + * Preload the default file system. No performance impact as we need to load the default file system anyway. + * Just do it earlier to avoid the potential deadlock. * - * This can be removed once the oldest JRE supported by Tomcat includes - * a fix. + * This can be removed once the oldest JRE supported by Tomcat includes a fix. */ FileSystems.getDefault(); // Look via a ServiceLoader for a Log implementation that has a // constructor taking the String name. ServiceLoader<Log> logLoader = ServiceLoader.load(Log.class); - Constructor<? extends Log> m=null; - for (Log log: logLoader) { - Class<? extends Log> c=log.getClass(); + Constructor<? extends Log> m = null; + for (Log log : logLoader) { + Class<? extends Log> c = log.getClass(); try { - m=c.getConstructor(String.class); + m = c.getConstructor(String.class); break; - } - catch (NoSuchMethodException | SecurityException e) { + } catch (NoSuchMethodException | SecurityException e) { throw new Error(e); } } - discoveredLogConstructor=m; + discoveredLogConstructor = m; } @@ -108,23 +99,22 @@ public class LogFactory { // only those 2 methods need to change to use a different direct logger. /** - * <p>Construct (if necessary) and return a <code>Log</code> instance, - * using the factory's current set of configuration attributes.</p> - * - * <p><strong>NOTE</strong> - Depending upon the implementation of - * the <code>LogFactory</code> you are using, the <code>Log</code> - * instance you are returned may or may not be local to the current - * application, and may or may not be returned again on a subsequent - * call with the same name argument.</p> - * - * @param name Logical name of the <code>Log</code> instance to be - * returned (the meaning of this name is only known to the underlying - * logging implementation that is being wrapped) + * <p> + * Construct (if necessary) and return a <code>Log</code> instance, using the factory's current set of configuration + * attributes. + * </p> + * <p> + * <strong>NOTE</strong> - Depending upon the implementation of the <code>LogFactory</code> you are using, the + * <code>Log</code> instance you are returned may or may not be local to the current application, and may or may not + * be returned again on a subsequent call with the same name argument. + * </p> + * + * @param name Logical name of the <code>Log</code> instance to be returned (the meaning of this name is only known + * to the underlying logging implementation that is being wrapped) * * @return A log instance with the requested name * - * @exception LogConfigurationException if a suitable <code>Log</code> - * instance cannot be returned + * @exception LogConfigurationException if a suitable <code>Log</code> instance cannot be returned */ public Log getInstance(String name) throws LogConfigurationException { if (discoveredLogConstructor == null) { @@ -140,18 +130,16 @@ public class LogFactory { /** - * Convenience method to derive a name from the specified class and - * call <code>getInstance(String)</code> with it. + * Convenience method to derive a name from the specified class and call <code>getInstance(String)</code> with it. * * @param clazz Class for which a suitable Log name will be derived * * @return A log instance with a name of clazz.getName() * - * @exception LogConfigurationException if a suitable <code>Log</code> - * instance cannot be returned + * @exception LogConfigurationException if a suitable <code>Log</code> instance cannot be returned */ public Log getInstance(Class<?> clazz) throws LogConfigurationException { - return getInstance( clazz.getName()); + return getInstance(clazz.getName()); } @@ -162,31 +150,28 @@ public class LogFactory { /** - * <p>Construct (if necessary) and return a <code>LogFactory</code> - * instance, using the following ordered lookup procedure to determine - * the name of the implementation class to be loaded.</p> + * <p> + * Construct (if necessary) and return a <code>LogFactory</code> instance, using the following ordered lookup + * procedure to determine the name of the implementation class to be loaded. + * </p> * <ul> - * <li>The <code>org.apache.commons.logging.LogFactory</code> system - * property.</li> + * <li>The <code>org.apache.commons.logging.LogFactory</code> system property.</li> * <li>The JDK 1.3 Service Discovery mechanism</li> - * <li>Use the properties file <code>commons-logging.properties</code> - * file, if found in the class path of this class. The configuration - * file is in standard <code>java.util.Properties</code> format and - * contains the fully qualified name of the implementation class - * with the key being the system property defined above.</li> + * <li>Use the properties file <code>commons-logging.properties</code> file, if found in the class path of this + * class. The configuration file is in standard <code>java.util.Properties</code> format and contains the fully + * qualified name of the implementation class with the key being the system property defined above.</li> * <li>Fall back to a default implementation class - * (<code>org.apache.commons.logging.impl.LogFactoryImpl</code>).</li> + * (<code>org.apache.commons.logging.impl.LogFactoryImpl</code>).</li> * </ul> - * - * <p><em>NOTE</em> - If the properties file method of identifying the - * <code>LogFactory</code> implementation class is utilized, all of the - * properties defined in this file will be set as configuration attributes - * on the corresponding <code>LogFactory</code> instance.</p> + * <p> + * <em>NOTE</em> - If the properties file method of identifying the <code>LogFactory</code> implementation class is + * utilized, all of the properties defined in this file will be set as configuration attributes on the corresponding + * <code>LogFactory</code> instance. + * </p> * * @return The singleton LogFactory instance * - * @exception LogConfigurationException if the implementation class is not - * available or cannot be instantiated. + * @exception LogConfigurationException if the implementation class is not available or cannot be instantiated. */ public static LogFactory getFactory() throws LogConfigurationException { return singleton; @@ -194,46 +179,37 @@ public class LogFactory { /** - * Convenience method to return a named logger, without the application - * having to care about factories. + * Convenience method to return a named logger, without the application having to care about factories. * * @param clazz Class from which a log name will be derived * * @return A log instance with a name of clazz.getName() * - * @exception LogConfigurationException if a suitable <code>Log</code> - * instance cannot be returned + * @exception LogConfigurationException if a suitable <code>Log</code> instance cannot be returned */ - public static Log getLog(Class<?> clazz) - throws LogConfigurationException { + public static Log getLog(Class<?> clazz) throws LogConfigurationException { return getFactory().getInstance(clazz); } /** - * Convenience method to return a named logger, without the application - * having to care about factories. + * Convenience method to return a named logger, without the application having to care about factories. * - * @param name Logical name of the <code>Log</code> instance to be - * returned (the meaning of this name is only known to the underlying - * logging implementation that is being wrapped) + * @param name Logical name of the <code>Log</code> instance to be returned (the meaning of this name is only known + * to the underlying logging implementation that is being wrapped) * * @return A log instance with the requested name * - * @exception LogConfigurationException if a suitable <code>Log</code> - * instance cannot be returned + * @exception LogConfigurationException if a suitable <code>Log</code> instance cannot be returned */ - public static Log getLog(String name) - throws LogConfigurationException { + public static Log getLog(String name) throws LogConfigurationException { return getFactory().getInstance(name); } /** - * Release any internal references to previously created {@link LogFactory} - * instances that have been associated with the specified class loader - * (if any), after calling the instance method <code>release()</code> on - * each of them. + * Release any internal references to previously created {@link LogFactory} instances that have been associated with + * the specified class loader (if any), after calling the instance method <code>release()</code> on each of them. * * @param classLoader ClassLoader for which to release the LogFactory */ @@ -241,8 +217,7 @@ public class LogFactory { // JULI's log manager looks at the current classLoader so there is no // need to use the passed in classLoader, the default implementation // does not so call reset in that case will break things - if (!LogManager.getLogManager().getClass().getName().equals( - "java.util.logging.LogManager")) { + if (!LogManager.getLogManager().getClass().getName().equals("java.util.logging.LogManager")) { LogManager.getLogManager().reset(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org