You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/01/16 19:36:53 UTC
[tomcat] branch 7.0.x updated: Align more closely with 8.5.x
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push:
new 00aef66 Align more closely with 8.5.x
00aef66 is described below
commit 00aef66ae661d5650e7f09e632aadbcd60784282
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jan 16 19:35:31 2020 +0000
Align more closely with 8.5.x
---
java/org/apache/juli/AsyncFileHandler.java | 36 +++++++++++++---------
java/org/apache/juli/ClassLoaderLogManager.java | 15 +++++----
java/org/apache/juli/DateFormatCache.java | 7 ++---
java/org/apache/juli/FileHandler.java | 24 +++++++++------
java/org/apache/juli/JdkLoggerFormatter.java | 4 ---
java/org/apache/juli/logging/DirectJDKLog.java | 30 ++++++------------
.../juli/logging/LogConfigurationException.java | 26 ++--------------
java/org/apache/juli/logging/package.html | 2 +-
8 files changed, 59 insertions(+), 85 deletions(-)
diff --git a/java/org/apache/juli/AsyncFileHandler.java b/java/org/apache/juli/AsyncFileHandler.java
index 44aa826..8429d2f 100644
--- a/java/org/apache/juli/AsyncFileHandler.java
+++ b/java/org/apache/juli/AsyncFileHandler.java
@@ -43,16 +43,27 @@ import java.util.logging.LogRecord;
*/
public class AsyncFileHandler extends FileHandler {
- public static final int OVERFLOW_DROP_LAST = 1;
- public static final int OVERFLOW_DROP_FIRST = 2;
- public static final int OVERFLOW_DROP_FLUSH = 3;
+ public static final int OVERFLOW_DROP_LAST = 1;
+ public static final int OVERFLOW_DROP_FIRST = 2;
+ public static final int OVERFLOW_DROP_FLUSH = 3;
public static final int OVERFLOW_DROP_CURRENT = 4;
- public static final int OVERFLOW_DROP_TYPE = Integer.parseInt(System.getProperty("org.apache.juli.AsyncOverflowDropType", "1"));
- public static final int DEFAULT_MAX_RECORDS = Integer.parseInt(System.getProperty("org.apache.juli.AsyncMaxRecordCount", "10000"));
- public static final int LOGGER_SLEEP_TIME = Integer.parseInt(System.getProperty("org.apache.juli.AsyncLoggerPollInterval", "1000"));
+ public static final int DEFAULT_OVERFLOW_DROP_TYPE = 1;
+ public static final int DEFAULT_MAX_RECORDS = 10000;
+ public static final int DEFAULT_LOGGER_SLEEP_TIME = 1000;
- protected static LinkedBlockingDeque<LogEntry> queue = new LinkedBlockingDeque<LogEntry>(DEFAULT_MAX_RECORDS);
+ public static final int OVERFLOW_DROP_TYPE = Integer.parseInt(
+ System.getProperty("org.apache.juli.AsyncOverflowDropType",
+ Integer.toString(DEFAULT_OVERFLOW_DROP_TYPE)));
+ public static final int MAX_RECORDS = Integer.parseInt(
+ System.getProperty("org.apache.juli.AsyncMaxRecordCount",
+ Integer.toString(DEFAULT_MAX_RECORDS)));
+ public static final int LOGGER_SLEEP_TIME = Integer.parseInt(
+ System.getProperty("org.apache.juli.AsyncLoggerPollInterval",
+ Integer.toString(DEFAULT_LOGGER_SLEEP_TIME)));
+
+ protected static LinkedBlockingDeque<LogEntry> queue =
+ new LinkedBlockingDeque<LogEntry>(DEFAULT_MAX_RECORDS);
protected static LoggerThread logger = new LoggerThread();
@@ -137,7 +148,6 @@ public class AsyncFileHandler extends FileHandler {
}
protected static class LoggerThread extends Thread {
- protected boolean run = true;
public LoggerThread() {
this.setDaemon(true);
this.setName("AsyncFileHandlerWriter-" + System.identityHashCode(this));
@@ -145,7 +155,7 @@ public class AsyncFileHandler extends FileHandler {
@Override
public void run() {
- while (run) {
+ while (true) {
try {
LogEntry entry = queue.poll(LOGGER_SLEEP_TIME, TimeUnit.MILLISECONDS);
if (entry != null) {
@@ -156,13 +166,13 @@ public class AsyncFileHandler extends FileHandler {
} catch (Exception x) {
x.printStackTrace();
}
- }//while
+ }
}
}
protected static class LogEntry {
- private LogRecord record;
- private AsyncFileHandler handler;
+ private final LogRecord record;
+ private final AsyncFileHandler handler;
public LogEntry(LogRecord record, AsyncFileHandler handler) {
super();
this.record = record;
@@ -177,7 +187,5 @@ public class AsyncFileHandler extends FileHandler {
return true;
}
}
-
}
-
}
diff --git a/java/org/apache/juli/ClassLoaderLogManager.java b/java/org/apache/juli/ClassLoaderLogManager.java
index 8cb7d07..e4c6886 100644
--- a/java/org/apache/juli/ClassLoaderLogManager.java
+++ b/java/org/apache/juli/ClassLoaderLogManager.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.juli;
import java.io.File;
@@ -328,7 +327,6 @@ public class ClassLoaderLogManager extends LogManager {
return result;
}
-
@Override
public void readConfiguration()
throws IOException, SecurityException {
@@ -411,6 +409,7 @@ public class ClassLoaderLogManager extends LogManager {
*
* @param classLoader The classloader for which we will retrieve or build the
* configuration
+ * @return the log configuration
*/
protected synchronized ClassLoaderLogInfo getClassLoaderInfo(ClassLoader classLoader) {
@@ -440,8 +439,8 @@ public class ClassLoaderLogManager extends LogManager {
/**
* Read configuration for the specified classloader.
*
- * @param classLoader
- * @throws IOException Error
+ * @param classLoader The classloader
+ * @throws IOException Error reading configuration
*/
protected synchronized void readConfiguration(ClassLoader classLoader)
throws IOException {
@@ -591,8 +590,8 @@ public class ClassLoaderLogManager extends LogManager {
}
try {
this.prefix.set(prefix);
- Handler handler =
- (Handler) classLoader.loadClass(handlerClassName).newInstance();
+ Handler handler = (Handler) classLoader.loadClass(
+ handlerClassName).getConstructor().newInstance();
// The specification strongly implies all configuration should be done
// during the creation of the handler object.
// This includes setting level, filter, formatter and encoding.
@@ -616,8 +615,8 @@ public class ClassLoaderLogManager extends LogManager {
/**
* Set parent child relationship between the two specified loggers.
*
- * @param logger
- * @param parent
+ * @param logger The logger
+ * @param parent The parent logger
*/
protected static void doSetParentLogger(final Logger logger,
final Logger parent) {
diff --git a/java/org/apache/juli/DateFormatCache.java b/java/org/apache/juli/DateFormatCache.java
index 6f1e373..a311472 100644
--- a/java/org/apache/juli/DateFormatCache.java
+++ b/java/org/apache/juli/DateFormatCache.java
@@ -49,9 +49,9 @@ public class DateFormatCache {
private final String format;
/* Number of cached entries */
- private int cacheSize = 0;
+ private final int cacheSize;
- private Cache cache;
+ private final Cache cache;
/**
* Replace the millisecond formatting character 'S' by
@@ -122,9 +122,6 @@ public class DateFormatCache {
private Cache(Cache parent) {
cache = new String[cacheSize];
- for (int i = 0; i < cacheSize; i++) {
- cache[i] = null;
- }
formatter = new SimpleDateFormat(format, Locale.US);
formatter.setTimeZone(TimeZone.getDefault());
this.parent = parent;
diff --git a/java/org/apache/juli/FileHandler.java b/java/org/apache/juli/FileHandler.java
index fde18a2..3b4c06d 100644
--- a/java/org/apache/juli/FileHandler.java
+++ b/java/org/apache/juli/FileHandler.java
@@ -94,20 +94,25 @@ import java.util.regex.Pattern;
* </ul>
*/
public class FileHandler extends Handler {
+
public static final int DEFAULT_MAX_DAYS = -1;
private static final ExecutorService DELETE_FILES_SERVICE =
Executors.newSingleThreadExecutor(new ThreadFactory() {
+ private static final String NAME_PREFIX = "FileHandlerLogFilesCleaner-";
private final boolean isSecurityEnabled;
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
- private final String namePrefix = "FileHandlerLogFilesCleaner-";
{
SecurityManager s = System.getSecurityManager();
- this.isSecurityEnabled = s != null;
- this.group = isSecurityEnabled ? s.getThreadGroup()
- : Thread.currentThread().getThreadGroup();
+ if (s == null) {
+ this.isSecurityEnabled = false;
+ this.group = Thread.currentThread().getThreadGroup();
+ } else {
+ this.isSecurityEnabled = true;
+ this.group = s.getThreadGroup();
+ }
}
@Override
@@ -130,7 +135,7 @@ public class FileHandler extends Handler {
.setContextClassLoader(getClass().getClassLoader());
}
Thread t = new Thread(group, r,
- namePrefix + threadNumber.getAndIncrement());
+ NAME_PREFIX + threadNumber.getAndIncrement());
t.setDaemon(true);
return t;
} finally {
@@ -365,8 +370,7 @@ public class FileHandler extends Handler {
private void configure() {
Timestamp ts = new Timestamp(System.currentTimeMillis());
- String tsString = ts.toString().substring(0, 19);
- date = tsString.substring(0, 10);
+ date = ts.toString().substring(0, 10);
String className = this.getClass().getName(); //allow classes to override
@@ -410,6 +414,7 @@ public class FileHandler extends Handler {
} catch (NumberFormatException ignore) {
//no op
}
+
// Get encoding for the logging file
String encoding = getProperty(className + ".encoding", null);
if (encoding != null && encoding.length() > 0) {
@@ -427,7 +432,7 @@ public class FileHandler extends Handler {
String filterName = getProperty(className + ".filter", null);
if (filterName != null) {
try {
- setFilter((Filter) cl.loadClass(filterName).newInstance());
+ setFilter((Filter) cl.loadClass(filterName).getConstructor().newInstance());
} catch (Exception e) {
// Ignore
}
@@ -437,7 +442,8 @@ public class FileHandler extends Handler {
String formatterName = getProperty(className + ".formatter", null);
if (formatterName != null) {
try {
- setFormatter((Formatter) cl.loadClass(formatterName).newInstance());
+ setFormatter((Formatter) cl.loadClass(
+ formatterName).getConstructor().newInstance());
} catch (Exception e) {
// Ignore and fallback to defaults
setFormatter(new SimpleFormatter());
diff --git a/java/org/apache/juli/JdkLoggerFormatter.java b/java/org/apache/juli/JdkLoggerFormatter.java
index e689979..48f61ac 100644
--- a/java/org/apache/juli/JdkLoggerFormatter.java
+++ b/java/org/apache/juli/JdkLoggerFormatter.java
@@ -14,14 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.juli;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
-
-
/**
* A more compact formatter.
*
@@ -109,5 +106,4 @@ public class JdkLoggerFormatter extends Formatter {
// Print to the appropriate destination
return buf.toString();
}
-
}
diff --git a/java/org/apache/juli/logging/DirectJDKLog.java b/java/org/apache/juli/logging/DirectJDKLog.java
index 0b407c1..5fd6aba 100644
--- a/java/org/apache/juli/logging/DirectJDKLog.java
+++ b/java/org/apache/juli/logging/DirectJDKLog.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.juli.logging;
import java.util.logging.ConsoleHandler;
@@ -24,43 +23,34 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Hardcoded java.util.logging commons-logging implementation.
- *
- * In addition, it curr
- *
+ * Hard-coded java.util.logging commons-logging implementation.
*/
class DirectJDKLog implements Log {
// no reason to hide this - but good reasons to not hide
public Logger logger;
- /** Alternate config reader and console format
- */
+ // Alternate config reader and console format
private static final String SIMPLE_FMT="java.util.logging.SimpleFormatter";
- private static final String SIMPLE_CFG="org.apache.juli.JdkLoggerConfig"; //doesn't exist
private static final String FORMATTER="org.apache.juli.formatter";
static {
- if( System.getProperty("java.util.logging.config.class") ==null &&
- System.getProperty("java.util.logging.config.file") ==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 {
- Class.forName(SIMPLE_CFG).newInstance();
- } catch( Throwable t ) {
- }
- try {
- Formatter fmt=(Formatter)Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).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("");
- Handler handlers[]=root.getHandlers();
- for( int i=0; i< handlers.length; i++ ) {
+ for (Handler handler : root.getHandlers()) {
// I only care about console - that's what's used in default config anyway
- if( handlers[i] instanceof ConsoleHandler ) {
- handlers[i].setFormatter(fmt);
+ if (handler instanceof ConsoleHandler) {
+ handler.setFormatter(fmt);
}
}
- } catch( Throwable t ) {
+ } catch (Throwable t) {
// maybe it wasn't included - the ugly default will be used.
}
diff --git a/java/org/apache/juli/logging/LogConfigurationException.java b/java/org/apache/juli/logging/LogConfigurationException.java
index af418f0..50301ee 100644
--- a/java/org/apache/juli/logging/LogConfigurationException.java
+++ b/java/org/apache/juli/logging/LogConfigurationException.java
@@ -56,7 +56,7 @@ public class LogConfigurationException extends RuntimeException {
* @param cause The underlying cause
*/
public LogConfigurationException(Throwable cause) {
- this( ((cause == null) ? null : cause.toString()), cause);
+ super(cause);
}
@@ -67,28 +67,6 @@ public class LogConfigurationException extends RuntimeException {
* @param cause The underlying cause
*/
public LogConfigurationException(String message, Throwable cause) {
-
- super(message);
- this.cause = cause; // Two-argument version requires JDK 1.4 or later
-
- }
-
-
- /**
- * The underlying cause of this exception.
- */
- protected Throwable cause = null;
-
-
- /**
- * Return the underlying cause of this exception (if any).
- */
- @Override
- public Throwable getCause() {
-
- return (this.cause);
-
+ super(message, cause);
}
-
-
}
diff --git a/java/org/apache/juli/logging/package.html b/java/org/apache/juli/logging/package.html
index 30afa40..99ab816 100644
--- a/java/org/apache/juli/logging/package.html
+++ b/java/org/apache/juli/logging/package.html
@@ -32,6 +32,6 @@ logging and use commons-logging-jdk.jar.</p>
</p>
<p>This package generates commons-logging-jdk14.jar - i.e. the java.util implementation
-of commons-logging api.<p>
+of commons-logging api.</p>
</body>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org