Minor Improvement: (#34)
* Change 'StringBuffer' by 'StringBuilder' * Fix javadoc * Remove redundant initializer * Use Empty array
This commit is contained in:
@@ -133,7 +133,7 @@ public abstract class LogFactory {
|
|||||||
* generated by LogFactory or LogFactoryImpl. When non-null,
|
* generated by LogFactory or LogFactoryImpl. When non-null,
|
||||||
* interesting events will be written to the specified object.
|
* interesting events will be written to the specified object.
|
||||||
*/
|
*/
|
||||||
private static PrintStream diagnosticsStream;
|
private static final PrintStream DIAGNOSTICS_STREAM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A string that gets prefixed to every message output by the
|
* A string that gets prefixed to every message output by the
|
||||||
@@ -1088,7 +1088,7 @@ public abstract class LogFactory {
|
|||||||
// has been specified. Several well known containers use this mechanism to adapt JCL
|
// has been specified. Several well known containers use this mechanism to adapt JCL
|
||||||
// to their native logging system.
|
// to their native logging system.
|
||||||
//
|
//
|
||||||
final StringBuffer msg = new StringBuffer();
|
final StringBuilder msg = new StringBuilder();
|
||||||
msg.append("The application has specified that a custom LogFactory implementation ");
|
msg.append("The application has specified that a custom LogFactory implementation ");
|
||||||
msg.append("should be used but Class '");
|
msg.append("should be used but Class '");
|
||||||
msg.append(factoryClass);
|
msg.append(factoryClass);
|
||||||
@@ -1503,7 +1503,7 @@ public abstract class LogFactory {
|
|||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
protected static boolean isDiagnosticsEnabled() {
|
protected static boolean isDiagnosticsEnabled() {
|
||||||
return diagnosticsStream != null;
|
return DIAGNOSTICS_STREAM != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1525,10 +1525,10 @@ public abstract class LogFactory {
|
|||||||
* @param msg is the diagnostic message to be output.
|
* @param msg is the diagnostic message to be output.
|
||||||
*/
|
*/
|
||||||
private static final void logDiagnostic(final String msg) {
|
private static final void logDiagnostic(final String msg) {
|
||||||
if (diagnosticsStream != null) {
|
if (DIAGNOSTICS_STREAM != null) {
|
||||||
diagnosticsStream.print(diagnosticPrefix);
|
DIAGNOSTICS_STREAM.print(diagnosticPrefix);
|
||||||
diagnosticsStream.println(msg);
|
DIAGNOSTICS_STREAM.println(msg);
|
||||||
diagnosticsStream.flush();
|
DIAGNOSTICS_STREAM.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1539,9 +1539,9 @@ public abstract class LogFactory {
|
|||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
protected static final void logRawDiagnostic(final String msg) {
|
protected static final void logRawDiagnostic(final String msg) {
|
||||||
if (diagnosticsStream != null) {
|
if (DIAGNOSTICS_STREAM != null) {
|
||||||
diagnosticsStream.println(msg);
|
DIAGNOSTICS_STREAM.println(msg);
|
||||||
diagnosticsStream.flush();
|
DIAGNOSTICS_STREAM.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1616,7 +1616,7 @@ public abstract class LogFactory {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (classLoader != null) {
|
if (classLoader != null) {
|
||||||
final StringBuffer buf = new StringBuffer(prefix + "ClassLoader tree:");
|
final StringBuilder buf = new StringBuilder(prefix + "ClassLoader tree:");
|
||||||
for(;;) {
|
for(;;) {
|
||||||
buf.append(objectId(classLoader));
|
buf.append(objectId(classLoader));
|
||||||
if (classLoader == systemClassLoader) {
|
if (classLoader == systemClassLoader) {
|
||||||
@@ -1704,7 +1704,7 @@ public abstract class LogFactory {
|
|||||||
classLoaderName = "UNKNOWN";
|
classLoaderName = "UNKNOWN";
|
||||||
}
|
}
|
||||||
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
|
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
|
||||||
diagnosticsStream = initDiagnostics();
|
DIAGNOSTICS_STREAM = initDiagnostics();
|
||||||
logClassLoaderEnvironment(LogFactory.class);
|
logClassLoaderEnvironment(LogFactory.class);
|
||||||
factories = createFactoryStore();
|
factories = createFactoryStore();
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
|
|||||||
@@ -68,6 +68,11 @@ public class LogSource {
|
|||||||
/** Constructor for current log class */
|
/** Constructor for current log class */
|
||||||
static protected Constructor logImplctor;
|
static protected Constructor logImplctor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An empty immutable {@code String} array.
|
||||||
|
*/
|
||||||
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
// ----------------------------------------------------- Class Initializers
|
// ----------------------------------------------------- Class Initializers
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -215,6 +220,6 @@ public class LogSource {
|
|||||||
* all logs known to me.
|
* all logs known to me.
|
||||||
*/
|
*/
|
||||||
static public String[] getLogNames() {
|
static public String[] getLogNames() {
|
||||||
return (String[]) logs.keySet().toArray(new String[logs.size()]);
|
return (String[]) logs.keySet().toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
private static final String PKG_IMPL="org.apache.commons.logging.impl.";
|
private static final String PKG_IMPL="org.apache.commons.logging.impl.";
|
||||||
private static final int PKG_LEN = PKG_IMPL.length();
|
private static final int PKG_LEN = PKG_IMPL.length();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An empty immutable {@code String} array.
|
||||||
|
*/
|
||||||
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
// ----------------------------------------------------------- Constructors
|
// ----------------------------------------------------------- Constructors
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,7 +259,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String[] getAttributeNames() {
|
public String[] getAttributeNames() {
|
||||||
return (String[]) attributes.keySet().toArray(new String[attributes.size()]);
|
return (String[]) attributes.keySet().toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1360,7 +1365,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!allowFlawedHierarchy) {
|
if (!allowFlawedHierarchy) {
|
||||||
final StringBuffer msg = new StringBuffer();
|
final StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Terminating logging for this context ");
|
msg.append("Terminating logging for this context ");
|
||||||
msg.append("due to bad log hierarchy. ");
|
msg.append("due to bad log hierarchy. ");
|
||||||
msg.append("You have more than one version of '");
|
msg.append("You have more than one version of '");
|
||||||
@@ -1373,7 +1378,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
final StringBuffer msg = new StringBuffer();
|
final StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Warning: bad log hierarchy. ");
|
msg.append("Warning: bad log hierarchy. ");
|
||||||
msg.append("You have more than one version of '");
|
msg.append("You have more than one version of '");
|
||||||
msg.append(Log.class.getName());
|
msg.append(Log.class.getName());
|
||||||
@@ -1383,7 +1388,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
} else {
|
} else {
|
||||||
// this is just a bad adapter class
|
// this is just a bad adapter class
|
||||||
if (!allowFlawedDiscovery) {
|
if (!allowFlawedDiscovery) {
|
||||||
final StringBuffer msg = new StringBuffer();
|
final StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Terminating logging for this context. ");
|
msg.append("Terminating logging for this context. ");
|
||||||
msg.append("Log class '");
|
msg.append("Log class '");
|
||||||
msg.append(badClass.getName());
|
msg.append(badClass.getName());
|
||||||
@@ -1396,7 +1401,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
final StringBuffer msg = new StringBuffer();
|
final StringBuilder msg = new StringBuilder();
|
||||||
msg.append("[WARNING] Log class '");
|
msg.append("[WARNING] Log class '");
|
||||||
msg.append(badClass.getName());
|
msg.append(badClass.getName());
|
||||||
msg.append("' does not implement the Log interface.");
|
msg.append("' does not implement the Log interface.");
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
static protected final String DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss:SSS zzz";
|
static protected final String DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss:SSS zzz";
|
||||||
|
|
||||||
/** Include the instance name in the log message? */
|
/** Include the instance name in the log message? */
|
||||||
static volatile protected boolean showLogName = false;
|
static volatile protected boolean showLogName;
|
||||||
|
|
||||||
/** Include the short name ( last component ) of the logger in the log
|
/** Include the short name ( last component ) of the logger in the log
|
||||||
* message. Defaults to true - otherwise we'll be lost in a flood of
|
* message. Defaults to true - otherwise we'll be lost in a flood of
|
||||||
@@ -95,7 +95,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
static volatile protected boolean showShortName = true;
|
static volatile protected boolean showShortName = true;
|
||||||
|
|
||||||
/** Include the current time in the log message */
|
/** Include the current time in the log message */
|
||||||
static volatile protected boolean showDateTime = false;
|
static volatile protected boolean showDateTime;
|
||||||
|
|
||||||
/** The date and time format to use in the log message */
|
/** The date and time format to use in the log message */
|
||||||
static volatile protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
|
static volatile protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
|
||||||
@@ -193,11 +193,11 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
// ------------------------------------------------------------- Attributes
|
// ------------------------------------------------------------- Attributes
|
||||||
|
|
||||||
/** The name of this simple log instance */
|
/** The name of this simple log instance */
|
||||||
protected volatile String logName = null;
|
protected volatile String logName;
|
||||||
/** The current log level */
|
/** The current log level */
|
||||||
protected volatile int currentLogLevel;
|
protected volatile int currentLogLevel;
|
||||||
/** The short name of this simple log instance */
|
/** The short name of this simple log instance */
|
||||||
private volatile String shortLogName = null;
|
private volatile String shortLogName;
|
||||||
|
|
||||||
// ------------------------------------------------------------ Constructor
|
// ------------------------------------------------------------ Constructor
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
/* ReferenceQueue we check for gc'd keys */
|
/* ReferenceQueue we check for gc'd keys */
|
||||||
private final ReferenceQueue queue = new ReferenceQueue();
|
private final ReferenceQueue queue = new ReferenceQueue();
|
||||||
/* Counter used to control how often we purge gc'd entries */
|
/* Counter used to control how often we purge gc'd entries */
|
||||||
private int changeCount = 0;
|
private int changeCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a WeakHashtable with the Hashtable default
|
* Constructs a WeakHashtable with the Hashtable default
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Clean implementation of list function of
|
* Clean implementation of list function of
|
||||||
* {@link java.utils.Collection} added in JDK 1.4
|
* {@link java.util.Collection} added in JDK 1.4
|
||||||
* @param en <code>Enumeration</code>, possibly null
|
* @param en <code>Enumeration</code>, possibly null
|
||||||
* @return <code>ArrayList</code> containing the enumerated
|
* @return <code>ArrayList</code> containing the enumerated
|
||||||
* elements in the enumerated order, not null
|
* elements in the enumerated order, not null
|
||||||
|
|||||||
Reference in New Issue
Block a user