I've just started using commons-logging, so I used SimpleLog to get started. When doing so I found that the output isn't consistent.
With the default settings (showlogname=false, showShortLogname=true) the output looks like this:
[DEBUG] CodeGenerator - -locale.language=sv
With altered settings (showlogname=true, showShortLogname=false) the output looks like this:
[DEBUG] se.dennislundberg.codegeneration.ui.CodeGenerator - locale.language=sv
As you can see in the first example there is an extra '-' before the log message.
I have attached a patch that corrects this. The patch renames the variable "prefix" to "shortLogName" and adds some JavaDoc for it. A couple of typos and some trailing whitespace are also fixed in the patch.
-- Dennis Lundberg
Index: logging/src/java/org/apache/commons/logging/impl/SimpleLog.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/SimpleLog.java,v
retrieving revision 1.14
diff -u -r1.14 SimpleLog.java
--- logging/src/java/org/apache/commons/logging/impl/SimpleLog.java 9 Oct 2003
21:37:47 -0000 1.14
+++ logging/src/java/org/apache/commons/logging/impl/SimpleLog.java 6 Jan 2004
23:45:38 -0000
@@ -93,7 +93,7 @@
* Set to <code>true</code> if you want the Log instance name to be
* included in output messages. Defaults to <code>false</code>.</li>
* <li><code>org.apache.commons.logging.simplelog.showShortLogname</code> -
- * Set to <code>true</code> if you want the last componet of the name to be
+ * Set to <code>true</code> if you want the last component of the name to be
* included in output messages. Defaults to <code>true</code>.</li>
* <li><code>org.apache.commons.logging.simplelog.showdatetime</code> -
* Set to <code>true</code> if you want the current date and time
@@ -158,7 +158,7 @@
public static final int LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1);
// ------------------------------------------------------------ Initializer
-
+
private static String getStringProperty(String name) {
String prop = null;
try {
@@ -214,9 +214,10 @@
/** The current log level */
protected int currentLogLevel;
- private String prefix=null;
+ /** The short name of this simple log instance */
+ private String shortLogName=null;
+
-
// ------------------------------------------------------------ Constructor
/**
@@ -308,7 +309,7 @@
buf.append(" ");
}
- // append a readable representation of the log leve
+ // append a readable representation of the log level
switch(type) {
case SimpleLog.LOG_LEVEL_TRACE: buf.append("[TRACE] "); break;
case SimpleLog.LOG_LEVEL_DEBUG: buf.append("[DEBUG] "); break;
@@ -320,12 +321,12 @@
// append the name of the log instance if so configured
if( showShortName) {
- if( prefix==null ) {
+ if( shortLogName==null ) {
// cut all but the last component of the name for both styles
- prefix = logName.substring( logName.lastIndexOf(".") +1) + " - ";
- prefix = prefix.substring( prefix.lastIndexOf("/") +1) + "-";
+ shortLogName = logName.substring( logName.lastIndexOf(".") +1);
+ shortLogName = shortLogName.substring( shortLogName.lastIndexOf("/")
+1);
}
- buf.append( prefix );
+ buf.append(String.valueOf(shortLogName)).append(" - ");
} else if(showLogName) {
buf.append(String.valueOf(logName)).append(" - ");
}
@@ -339,8 +340,8 @@
buf.append(t.toString());
buf.append(">");
- java.io.StringWriter sw= new java.io.StringWriter(1024);
- java.io.PrintWriter pw= new java.io.PrintWriter(sw);
+ java.io.StringWriter sw= new java.io.StringWriter(1024);
+ java.io.PrintWriter pw= new java.io.PrintWriter(sw);
t.printStackTrace(pw);
pw.close();
buf.append(sw.toString());
@@ -579,7 +580,7 @@
/**
* Return the thread context class loader if available.
* Otherwise return null.
- *
+ *
* The thread context class loader is available for JDK 1.2
* or later, if certain security conditions are met.
*
@@ -594,7 +595,7 @@
try {
// Are we running on a JDK 1.2 or later system?
Method method = Thread.class.getMethod("getContextClassLoader", null);
-
+
// Get the thread context class loader (if there is one)
try {
classLoader = (ClassLoader)method.invoke(Thread.currentThread(),
null);
@@ -605,12 +606,12 @@
* InvocationTargetException is thrown by 'invoke' when
* the method being invoked (getContextClassLoader) throws
* an exception.
- *
+ *
* getContextClassLoader() throws SecurityException when
* the context class loader isn't an ancestor of the
* calling class's class loader, or if security
* permissions are restricted.
- *
+ *
* In the first case (not related), we want to ignore and
* keep going. We cannot help but also ignore the second
* with the logic below, but other calls elsewhere (to
@@ -631,7 +632,7 @@
; // ignore
}
}
-
+
if (classLoader == null) {
classLoader = SimpleLog.class.getClassLoader();
}
@@ -639,7 +640,7 @@
// Return the selected class loader
return classLoader;
}
-
+
private static InputStream getResourceAsStream(final String name)
{
return (InputStream)AccessController.doPrivileged(--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
