Added the facilities for logging a stack trace.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@25 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DefaultLogProvider.java,v 1.1 2000/12/06 03:21:59 mdb Exp $
|
// $Id: DefaultLogProvider.java,v 1.2 2000/12/07 06:13:59 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
@@ -9,6 +9,9 @@ import java.util.Hashtable;
|
|||||||
* If no log provider is registered with the log services, the default
|
* If no log provider is registered with the log services, the default
|
||||||
* provider will be used. The default provider simple logs messages to
|
* provider will be used. The default provider simple logs messages to
|
||||||
* <code>System.err</code> and manages log levels in a simplistic way.
|
* <code>System.err</code> and manages log levels in a simplistic way.
|
||||||
|
*
|
||||||
|
* @see Log
|
||||||
|
* @see LogProvider
|
||||||
*/
|
*/
|
||||||
public class DefaultLogProvider implements LogProvider
|
public class DefaultLogProvider implements LogProvider
|
||||||
{
|
{
|
||||||
@@ -21,6 +24,16 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void logStackTrace (int level, String moduleName, Throwable t)
|
||||||
|
{
|
||||||
|
Integer tlevel = (Integer)_levels.get(moduleName);
|
||||||
|
if ((tlevel != null && level >= tlevel.intValue()) ||
|
||||||
|
(level >= _level)) {
|
||||||
|
System.err.println(moduleName + ": " + t.getMessage());
|
||||||
|
t.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setLevel (String moduleName, int level)
|
public void setLevel (String moduleName, int level)
|
||||||
{
|
{
|
||||||
_levels.put(moduleName, new Integer(level));
|
_levels.put(moduleName, new Integer(level));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Log.java,v 1.2 2000/12/06 03:21:59 mdb Exp $
|
// $Id: Log.java,v 1.3 2000/12/07 06:13:59 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
@@ -57,6 +57,16 @@ public final class Log
|
|||||||
_provider.log(WARNING, _moduleName, message);
|
_provider.log(WARNING, _moduleName, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs the stack trace of the supplied throwable at the specified
|
||||||
|
* level (if the current log level for this module is at or below the
|
||||||
|
* specified level).
|
||||||
|
*/
|
||||||
|
public void logStackTrace (int level, Throwable t)
|
||||||
|
{
|
||||||
|
_provider.logStackTrace(level, _moduleName, t);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the log level of the specified module to the specified
|
* Sets the log level of the specified module to the specified
|
||||||
* value. The log level indicates which messages are logged and which
|
* value. The log level indicates which messages are logged and which
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: LogProvider.java,v 1.1 2000/12/06 00:24:46 mdb Exp $
|
// $Id: LogProvider.java,v 1.2 2000/12/07 06:13:59 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
@@ -16,6 +16,13 @@ public interface LogProvider
|
|||||||
*/
|
*/
|
||||||
public void log (int level, String moduleName, String message);
|
public void log (int level, String moduleName, String message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log the stack trace of the supplied throwable at the specified
|
||||||
|
* level for the specified module, if messages are enabled for that
|
||||||
|
* particular combination.
|
||||||
|
*/
|
||||||
|
public void logStackTrace (int level, String moduleName, Throwable t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the log level for the specified module to the specified
|
* Set the log level for the specified module to the specified
|
||||||
* level. The log services assume that all messages at or higher than
|
* level. The log services assume that all messages at or higher than
|
||||||
|
|||||||
Reference in New Issue
Block a user