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:
parent
9e4b13a79e
commit
d9e27aedb6
@ -1,3 +1,9 @@
|
|||||||
|
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
|
||||||
2003-08-28 Mohan Embar <gnustuff@thisiscool.com>
|
2003-08-28 Mohan Embar <gnustuff@thisiscool.com>
|
||||||
|
|
||||||
* win32.cc: fixed tab, indentation and whitespace
|
* win32.cc: fixed tab, indentation and whitespace
|
||||||
|
@ -52,6 +52,7 @@ import java.util.Properties;
|
|||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,6 +168,7 @@ public class LogManager
|
|||||||
* the order in which classes are initialized.
|
* the order in which classes are initialized.
|
||||||
*/
|
*/
|
||||||
Logger.getLogger("global").setParent(rootLogger);
|
Logger.getLogger("global").setParent(rootLogger);
|
||||||
|
Logger.getLogger("global").setUseParentHandlers(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -520,7 +522,7 @@ public class LogManager
|
|||||||
|
|
||||||
public synchronized void readConfiguration(InputStream inputStream)
|
public synchronized void readConfiguration(InputStream inputStream)
|
||||||
throws IOException, SecurityException
|
throws IOException, SecurityException
|
||||||
{
|
{
|
||||||
Properties newProperties;
|
Properties newProperties;
|
||||||
Enumeration keys;
|
Enumeration keys;
|
||||||
|
|
||||||
@ -532,12 +534,36 @@ public class LogManager
|
|||||||
|
|
||||||
while (keys.hasMoreElements())
|
while (keys.hasMoreElements())
|
||||||
{
|
{
|
||||||
String key = (String) keys.nextElement();
|
String key = ((String) keys.nextElement()).trim();
|
||||||
String value = newProperties.getProperty(key);
|
String value = newProperties.getProperty(key);
|
||||||
|
|
||||||
if (value == null)
|
if (value == null)
|
||||||
continue;
|
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"))
|
if (key.endsWith(".level"))
|
||||||
{
|
{
|
||||||
String loggerName = key.substring(0, key.length() - 6);
|
String loggerName = key.substring(0, key.length() - 6);
|
||||||
@ -550,6 +576,7 @@ public class LogManager
|
|||||||
}
|
}
|
||||||
catch (Exception _)
|
catch (Exception _)
|
||||||
{
|
{
|
||||||
|
//System.out.println("[LogManager.readConfiguration] "+_);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -589,9 +589,10 @@ public class Logger
|
|||||||
String message,
|
String message,
|
||||||
Object param)
|
Object param)
|
||||||
{
|
{
|
||||||
|
StackTraceElement caller = getCallerStackFrame();
|
||||||
logp(level,
|
logp(level,
|
||||||
/* sourceClass*/ null,
|
caller.getClassName(),
|
||||||
/* sourceMethod */ null,
|
caller.getMethodName(),
|
||||||
message,
|
message,
|
||||||
param);
|
param);
|
||||||
}
|
}
|
||||||
@ -601,9 +602,10 @@ public class Logger
|
|||||||
String message,
|
String message,
|
||||||
Object[] params)
|
Object[] params)
|
||||||
{
|
{
|
||||||
|
StackTraceElement caller = getCallerStackFrame();
|
||||||
logp(level,
|
logp(level,
|
||||||
/* sourceClass*/ null,
|
caller.getClassName(),
|
||||||
/* sourceMethod */ null,
|
caller.getMethodName(),
|
||||||
message,
|
message,
|
||||||
params);
|
params);
|
||||||
}
|
}
|
||||||
@ -613,9 +615,10 @@ public class Logger
|
|||||||
String message,
|
String message,
|
||||||
Throwable thrown)
|
Throwable thrown)
|
||||||
{
|
{
|
||||||
|
StackTraceElement caller = getCallerStackFrame();
|
||||||
logp(level,
|
logp(level,
|
||||||
/* sourceClass*/ null,
|
caller.getClassName(),
|
||||||
/* sourceMethod */ null,
|
caller.getMethodName(),
|
||||||
message,
|
message,
|
||||||
thrown);
|
thrown);
|
||||||
}
|
}
|
||||||
@ -1164,4 +1167,23 @@ public class Logger
|
|||||||
|
|
||||||
this.parent = parent;
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,9 @@ public class SimpleFormatter
|
|||||||
|
|
||||||
buf.append(dateFormat.format(new Date(record.getMillis())));
|
buf.append(dateFormat.format(new Date(record.getMillis())));
|
||||||
buf.append(' ');
|
buf.append(' ');
|
||||||
buf.append(record.getLoggerName());
|
buf.append(record.getSourceClassName());
|
||||||
|
buf.append(' ');
|
||||||
|
buf.append(record.getSourceMethodName());
|
||||||
buf.append(lineSep);
|
buf.append(lineSep);
|
||||||
|
|
||||||
buf.append(record.getLevel());
|
buf.append(record.getLevel());
|
||||||
|
Loading…
Reference in New Issue
Block a user