summaryrefslogtreecommitdiff
path: root/libjava/java/util/logging/Logger.java
diff options
context:
space:
mode:
authorIngo Proetel <proetel@aicas.com>2003-08-31 16:52:16 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2003-08-31 16:52:16 +0000
commitd9e27aedb6d02637efff40ed95ab0131100cb3db (patch)
tree4cef7ba67443936ec02bcbb5538c6a5f2826c8ab /libjava/java/util/logging/Logger.java
parent9e4b13a79edbe22a7a4d20f0d4aefe59b9b2380b (diff)
Logger.java: provide class and method information
2003-08-31 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 From-SVN: r70960
Diffstat (limited to 'libjava/java/util/logging/Logger.java')
-rw-r--r--libjava/java/util/logging/Logger.java34
1 files changed, 28 insertions, 6 deletions
diff --git a/libjava/java/util/logging/Logger.java b/libjava/java/util/logging/Logger.java
index e142e201f70..3c194785c5f 100644
--- a/libjava/java/util/logging/Logger.java
+++ b/libjava/java/util/logging/Logger.java
@@ -589,9 +589,10 @@ public class Logger
String message,
Object param)
{
+ StackTraceElement caller = getCallerStackFrame();
logp(level,
- /* sourceClass*/ null,
- /* sourceMethod */ null,
+ caller.getClassName(),
+ caller.getMethodName(),
message,
param);
}
@@ -601,9 +602,10 @@ public class Logger
String message,
Object[] params)
{
+ StackTraceElement caller = getCallerStackFrame();
logp(level,
- /* sourceClass*/ null,
- /* sourceMethod */ null,
+ caller.getClassName(),
+ caller.getMethodName(),
message,
params);
}
@@ -613,9 +615,10 @@ public class Logger
String message,
Throwable thrown)
{
+ StackTraceElement caller = getCallerStackFrame();
logp(level,
- /* sourceClass*/ null,
- /* sourceMethod */ null,
+ caller.getClassName(),
+ caller.getMethodName(),
message,
thrown);
}
@@ -1164,4 +1167,23 @@ public class Logger
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];
+ }
+
}