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
This commit is contained in:
Ingo Proetel 2003-08-31 16:52:16 +00:00 committed by Michael Koch
parent 9e4b13a79e
commit d9e27aedb6
4 changed files with 68 additions and 11 deletions

View file

@ -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];
}
}