This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: java.util.logging
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Sun, 31 Aug 2003 18:53:20 +0200
- Subject: Patch: java.util.logging
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I commited a patch to java.util.logging to merge it again with
classpath.
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/UigDWSOgCCdjSDsRAvpdAJ44CpmE+mnN6sjqVYzX0IcbcBLotgCgkyl+
XFRNgvR9ddMoa6J3EOzFmLw=
=VBt8
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2129
diff -u -b -B -r1.2129 ChangeLog
--- ChangeLog 29 Aug 2003 04:20:59 -0000 1.2129
+++ ChangeLog 30 Aug 2003 18:22:09 -0000
@@ -1,3 +1,9 @@
+2003-08-30 Ingo Proetel <proetel@aicas.com>
+
+ * java/util/logging/Logger.java: provide class and method information
+ * java/util/logging/LogManager.java: create handlers
+ * java/util/logging/SimpleFormatter.java: print souceClassName and
+ sourceMethodName
2003-08-28 Mohan Embar <gnustuff@thisiscool.com>
* win32.cc: fixed tab, indentation and whitespace
Index: java/util/logging/SimpleFormatter.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/logging/SimpleFormatter.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 SimpleFormatter.java
--- java/util/logging/SimpleFormatter.java 21 Jun 2003 10:31:55 -0000 1.1
+++ java/util/logging/SimpleFormatter.java 30 Aug 2003 18:22:09 -0000
@@ -106,7 +106,9 @@
buf.append(dateFormat.format(new Date(record.getMillis())));
buf.append(' ');
- buf.append(record.getLoggerName());
+ buf.append(record.getSourceClassName());
+ buf.append(' ');
+ buf.append(record.getSourceMethodName());
buf.append(lineSep);
buf.append(record.getLevel());
Index: java/util/logging/Logger.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/logging/Logger.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 Logger.java
--- java/util/logging/Logger.java 21 Jun 2003 10:31:55 -0000 1.1
+++ java/util/logging/Logger.java 30 Aug 2003 18:22:09 -0000
@@ -589,9 +589,10 @@
String message,
Object param)
{
+ StackTraceElement caller = getCallerStackFrame();
logp(level,
- /* sourceClass*/ null,
- /* sourceMethod */ null,
+ caller.getClassName(),
+ caller.getMethodName(),
message,
param);
}
@@ -601,9 +602,10 @@
String message,
Object[] params)
{
+ StackTraceElement caller = getCallerStackFrame();
logp(level,
- /* sourceClass*/ null,
- /* sourceMethod */ null,
+ caller.getClassName(),
+ caller.getMethodName(),
message,
params);
}
@@ -613,9 +615,10 @@
String message,
Throwable thrown)
{
+ StackTraceElement caller = getCallerStackFrame();
logp(level,
- /* sourceClass*/ null,
- /* sourceMethod */ null,
+ caller.getClassName(),
+ caller.getMethodName(),
message,
thrown);
}
@@ -1164,4 +1167,23 @@
this.parent = parent;
}
+
+ /**
+ * Gets the StackTraceElement of the first class that is not this class.
+ * That should be the initial caller of a logging method.
+ * @return caller of the initial looging method
+ */
+ private StackTraceElement getCallerStackFrame()
+ {
+ Throwable t = new Throwable();
+ StackTraceElement[] stackTrace = t.getStackTrace();
+ int index = 0;
+ // skip to stackentries until this class
+ while(!stackTrace[index].getClassName().equals(getClass().getName())){index++;}
+ // skip the stackentries of this class
+ while(stackTrace[index].getClassName().equals(getClass().getName())){index++;}
+
+ return stackTrace[index];
+ }
+
}
Index: java/util/logging/LogManager.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/logging/LogManager.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 LogManager.java
--- java/util/logging/LogManager.java 21 Jun 2003 10:31:55 -0000 1.1
+++ java/util/logging/LogManager.java 30 Aug 2003 18:22:11 -0000
@@ -52,6 +52,7 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
+import java.util.StringTokenizer;
import java.lang.ref.WeakReference;
/**
@@ -167,6 +168,7 @@
* the order in which classes are initialized.
*/
Logger.getLogger("global").setParent(rootLogger);
+ Logger.getLogger("global").setUseParentHandlers(true);
}
@@ -532,12 +534,36 @@
while (keys.hasMoreElements())
{
- String key = (String) keys.nextElement();
+ String key = ((String) keys.nextElement()).trim();
String value = newProperties.getProperty(key);
if (value == null)
continue;
+ value = value.trim();
+
+ if("handlers".equals(key))
+ {
+ StringTokenizer tokenizer = new StringTokenizer(value);
+ while(tokenizer.hasMoreTokens())
+ {
+ String handlerName = tokenizer.nextToken();
+ try
+ {
+ Class handlerClass = Class.forName(handlerName);
+ getLogger("").addHandler((Handler)handlerClass.newInstance());
+ }
+ catch (ClassCastException ex)
+ {
+ System.err.println("[LogManager] class " + handlerName + " is not subclass of java.util.logging.Handler");
+ }
+ catch (Exception ex)
+ {
+ //System.out.println("[LogManager.readConfiguration]"+ex);
+ }
+ }
+ }
+
if (key.endsWith(".level"))
{
String loggerName = key.substring(0, key.length() - 6);
@@ -550,6 +576,7 @@
}
catch (Exception _)
{
+ //System.out.println("[LogManager.readConfiguration] "+_);
}
continue;
}