summaryrefslogtreecommitdiff
path: root/gnu/classpath/debug
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2013-02-26 09:45:40 +1100
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2013-02-26 09:45:40 +1100
commita285ee5bd7f796fde7ac2a4524d3789dc952ea73 (patch)
tree05528aea5d31eb96e915c8bd74ec072d6d16a7a9 /gnu/classpath/debug
parent2a0cb4d76201ee1e6c9a879056e5ac0aea00a7b1 (diff)
downloadclasspath-a285ee5bd7f796fde7ac2a4524d3789dc952ea73.tar.gz
Implement javax.tools.ToolProvider using ecj. Cleanup and make more use of Classpath logging mechanism.
Signed-off-by: Andrew John Hughes <gnu_andrew@member.fsf.org>
Diffstat (limited to 'gnu/classpath/debug')
-rw-r--r--gnu/classpath/debug/Component.java25
-rw-r--r--gnu/classpath/debug/PreciseFilter.java14
-rw-r--r--gnu/classpath/debug/SystemLogger.java61
3 files changed, 87 insertions, 13 deletions
diff --git a/gnu/classpath/debug/Component.java b/gnu/classpath/debug/Component.java
index 3cad8a2a7..eb841f441 100644
--- a/gnu/classpath/debug/Component.java
+++ b/gnu/classpath/debug/Component.java
@@ -74,7 +74,7 @@ public final class Component extends Level
* Signifies that everything should be logged. This should be used to
* enable or disable levels only; logging code should not use it.
*/
- public static final Component EVERYTHING = new Component ("*", 0, 11);
+ public static final Component EVERYTHING = new Component ("*", 0, 13);
/**
* Signifies that all SSL related messages should be logged. This should
@@ -86,22 +86,22 @@ public final class Component extends Level
/**
* Traces the progression of an SSL handshake.
*/
- public static final Component SSL_HANDSHAKE = new Component ("SSL HANDSHAKE", 0);
+ public static final Component SSL_HANDSHAKE = new Component ("SSL_HANDSHAKE", 0);
/**
* Traces record layer messages during SSL communications.
*/
- public static final Component SSL_RECORD_LAYER = new Component ("SSL RECORD LAYER", 1);
+ public static final Component SSL_RECORD_LAYER = new Component ("SSL_RECORD_LAYER", 1);
/**
* Trace details about the SSL key exchange.
*/
- public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2);
+ public static final Component SSL_KEY_EXCHANGE = new Component ("SSL_KEY_EXCHANGE", 2);
/**
* Trace running of delegated tasks.
*/
- public static final Component SSL_DELEGATED_TASK = new Component ("SSL DELEGATED TASK", 3);
+ public static final Component SSL_DELEGATED_TASK = new Component ("SSL_DELEGATED_TASK", 3);
/* Index 4 reserved for future use by SSL components. */
@@ -126,6 +126,21 @@ public final class Component extends Level
*/
public static final Component IPP = new Component ("IPP", 10);
+ /**
+ * Service loading.
+ */
+ public static final Component SERVICE_LOADING = new Component("SERVICE_LOADING", 11, 13);
+
+ /**
+ * Service loading warnings.
+ */
+ public static final Component SERVICE_LOADING_WARNING = new Component("SERVICE_LOADING_WARNING", 11);
+
+ /**
+ * Service loading verbose messages.
+ */
+ public static final Component SERVICE_LOADING_VERBOSE = new Component("SERVICE_LOADING_VERBOSE ", 12);
+
private final int startIndex;
private final int endIndex;
diff --git a/gnu/classpath/debug/PreciseFilter.java b/gnu/classpath/debug/PreciseFilter.java
index 91f5a9e6c..cfce6130d 100644
--- a/gnu/classpath/debug/PreciseFilter.java
+++ b/gnu/classpath/debug/PreciseFilter.java
@@ -40,6 +40,7 @@ package gnu.classpath.debug;
import java.util.BitSet;
import java.util.logging.Filter;
+import java.util.logging.Level;
import java.util.logging.LogRecord;
public final class PreciseFilter implements Filter
@@ -93,13 +94,10 @@ public final class PreciseFilter implements Filter
public boolean isLoggable (final LogRecord record)
{
- try
- {
- return isEnabled ((Component) record.getLevel ());
- }
- catch (ClassCastException cce)
- {
- return true;
- }
+ Level level = record.getLevel();
+ if (level instanceof Component)
+ return isEnabled ((Component) level);
+ return true;
}
+
}
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>&#x201c;Could not
+ * load {0}.&#x201d;</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);
+ }
+
}