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/03/04 14:18:24 UTC
[commons-logging] branch master updated: Use StringBuilder instead of StringBuffer for internal processing
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
The following commit(s) were added to refs/heads/master by this push:
new 6888105 Use StringBuilder instead of StringBuffer for internal processing
6888105 is described below
commit 6888105f9e2062a3c9c185d0a50908ecd56f211f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 4 09:18:20 2023 -0500
Use StringBuilder instead of StringBuffer for internal processing
---
.../commons/logging/impl/LogFactoryImpl.java | 4 ++--
.../org/apache/commons/logging/impl/SimpleLog.java | 22 ++++++++++++++++++----
2 files changed, 20 insertions(+), 6 deletions(-)
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 6376b49..190e889 100644
--- a/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
+++ b/src/main/java/org/apache/commons/logging/impl/LogFactoryImpl.java
@@ -808,7 +808,7 @@ public class LogFactoryImpl extends LogFactory {
logCategory,
true);
if (result == null) {
- final StringBuffer messageBuffer = new StringBuffer("User-specified log class '");
+ final StringBuilder messageBuffer = new StringBuilder("User-specified log class '");
messageBuffer.append(specifiedLogClassName);
messageBuffer.append("' cannot be found or is not useable.");
@@ -876,7 +876,7 @@ public class LogFactoryImpl extends LogFactory {
* @param name the (trimmed) name to be test against the candidate, not null
* @param candidate the candidate name (not null)
*/
- private void informUponSimilarName(final StringBuffer messageBuffer, final String name,
+ private void informUponSimilarName(final StringBuilder messageBuffer, final String name,
final String candidate) {
if (name.equals(candidate)) {
// Don't suggest a name that is exactly the same as the one the
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 331db46..ca47dc1 100644
--- a/src/main/java/org/apache/commons/logging/impl/SimpleLog.java
+++ b/src/main/java/org/apache/commons/logging/impl/SimpleLog.java
@@ -19,7 +19,9 @@ package org.apache.commons.logging.impl;
import java.io.IOException;
import java.io.InputStream;
+import java.io.PrintWriter;
import java.io.Serializable;
+import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
@@ -277,7 +279,7 @@ public class SimpleLog implements Log, Serializable {
*/
protected void log(final int type, final Object message, final Throwable t) {
// Use a string buffer for better performance
- final StringBuffer buf = new StringBuffer();
+ final StringBuilder buf = new StringBuilder();
// Append date-time if so configured
if(showDateTime) {
@@ -321,8 +323,8 @@ public class SimpleLog implements Log, Serializable {
buf.append(t.toString());
buf.append(">");
- final java.io.StringWriter sw = new java.io.StringWriter(1024);
- final java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ final StringWriter sw = new StringWriter(1024);
+ final PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.close();
buf.append(sw.toString());
@@ -344,6 +346,18 @@ public class SimpleLog implements Log, Serializable {
System.err.println(buffer.toString());
}
+ /**
+ * Write the content of the message accumulated in the specified
+ * {@code StringBuffer} to the appropriate output destination. The
+ * default implementation writes to {@code System.err}.
+ *
+ * @param buffer A {@code StringBuffer} containing the accumulated
+ * text to be logged
+ */
+ private void write(final Object buffer) {
+ System.err.println(buffer.toString());
+ }
+
/**
* Is the given log level currently enabled?
*
@@ -612,7 +626,7 @@ public class SimpleLog implements Log, Serializable {
// Get the thread context class loader (if there is one)
try {
- classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Class[]) null);
+ classLoader = (ClassLoader) method.invoke(Thread.currentThread(), (Class[]) null);
} catch (final IllegalAccessException e) {
// ignore
} catch (final InvocationTargetException e) {