diff options
Diffstat (limited to 'gnu/classpath/debug/SystemLogger.java')
-rw-r--r-- | gnu/classpath/debug/SystemLogger.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/gnu/classpath/debug/SystemLogger.java b/gnu/classpath/debug/SystemLogger.java index eaca0fe98..d0587c055 100644 --- a/gnu/classpath/debug/SystemLogger.java +++ b/gnu/classpath/debug/SystemLogger.java @@ -41,9 +41,14 @@ package gnu.classpath.debug; import gnu.java.security.action.GetPropertyAction; import java.security.AccessController; + import java.util.StringTokenizer; + +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.logging.LogRecord; public final class SystemLogger extends Logger { @@ -51,7 +56,13 @@ public final class SystemLogger extends Logger static { + SYSTEM.setLevel (Level.FINE); // So selection is left to filter SYSTEM.setFilter (PreciseFilter.GLOBAL); + Handler handler = new ConsoleHandler(); + handler.setLevel(Level.FINE); + handler.setFilter(PreciseFilter.GLOBAL); + SYSTEM.addHandler(handler); + SYSTEM.setUseParentHandlers(false); String defaults = (String) AccessController.doPrivileged (new GetPropertyAction("gnu.classpath.debug.components")); @@ -99,4 +110,54 @@ public final class SystemLogger extends Logger { log(level, format, args); } + + /** + * Passes a log message to the <code>java.util.logging</code> + * framework. This call returns very quickly if no log message will + * be produced, so there is not much overhead in the standard case. + * + * @param level the severity of the message, for instance {@link + * Component#SERVICE_LOGGING_WARNING}. + * @param sourceClass the name of the class that issued the logging + * request. + * @param sourceMethod the name of the method that issued the logging + * request. + * @param t a Throwable that is associated with the log record, or + * <code>null</code> if the log message is not associated with a + * Throwable. + * @param msg the log message, for instance <code>“Could not + * load {0}.”</code> + * @param params the parameter(s) for the log message, or + * <code>null</code> if <code>msg</code> does not specify any + * parameters. If <code>param</code> is not an array, an array with + * <code>param</code> as its single element gets passed to the + * logging framework. + */ + public void logp(Component level, String sourceClass, String sourceMethod, + Throwable t, String msg, Object... params) + { + LogRecord rec; + + // Return quickly if no log message will be produced. + if (!PreciseFilter.GLOBAL.isEnabled(level)) + return; + + rec = new LogRecord(level, msg); + if (params != null) + rec.setParameters(params); + + rec.setThrown(t); + + // While java.util.logging can sometimes infer the class and + // method of the caller, this automatic inference is not reliable + // on highly optimizing VMs. Also, log messages make more sense to + // developers when they display a public method in a public class; + // otherwise, they might feel tempted to figure out the internals + // in order to understand the problem. + rec.setSourceClassName(sourceClass); + rec.setSourceMethodName(sourceMethod); + + log(rec); + } + } |