/hg/icedtea-web: Add logging for applet exceptions.

asu at icedtea.classpath.org asu at icedtea.classpath.org
Mon Jan 17 10:44:53 PST 2011


changeset 98215ab000dd in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=98215ab000dd
author: Andrew Su <asu at redhat.com>
date: Mon Jan 17 13:44:31 2011 -0500

	Add logging for applet exceptions.


diffstat:

4 files changed, 113 insertions(+)
ChangeLog                                |    8 ++++
netx/net/sourceforge/jnlp/AppletLog.java |   52 ++++++++++++++++++++++++++++++
netx/net/sourceforge/jnlp/Log.java       |   42 ++++++++++++++++++++++++
netx/net/sourceforge/jnlp/NetxPanel.java |   11 ++++++

diffs (145 lines):

diff -r ce755342e8e8 -r 98215ab000dd ChangeLog
--- a/ChangeLog	Fri Jan 14 11:14:46 2011 -0500
+++ b/ChangeLog	Mon Jan 17 13:44:31 2011 -0500
@@ -1,3 +1,11 @@ 2011-01-14  Andrew Su  <asu at redhat.com>
+2011-01-17  Andrew Su  <asu at redhat.com>
+
+	* netx/net/sourceforge/jnlp/NetxPanel.java:
+	(showAppletException): Override, adds logging to file then proceed
+	with showAppletException in sun.applet.AppletPanel.
+	* netx/net/sourceforge/jnlp/AppletLog.java: New class.
+	* netx/net/sourceforge/jnlp/Log.java: New class.
+
 2011-01-14  Andrew Su  <asu at redhat.com>
 
 	* Makefile.am: Added net.sourceforge.jnlp.config and
diff -r ce755342e8e8 -r 98215ab000dd netx/net/sourceforge/jnlp/AppletLog.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netx/net/sourceforge/jnlp/AppletLog.java	Mon Jan 17 13:44:31 2011 -0500
@@ -0,0 +1,52 @@
+package net.sourceforge.jnlp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.logging.FileHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.XMLFormatter;
+
+/**
+ * This class writes log information to file.
+ * 
+ * @author Andrew Su (asu at redhat.com, andrew.su at utoronto.ca)
+ * 
+ */
+class AppletLog extends Log {
+    private static Logger logger;
+    static {
+        try {
+            // If logging is enabled, we create logger.
+            if (enableLogging) {
+                String fn = icedteaLogDir + "plugin" + java.lang.System.currentTimeMillis() + ".log";
+                boolean append = false;
+                FileHandler fh = new FileHandler(fn, append);
+                fh.setFormatter(new XMLFormatter());
+                String logClassName = AppletLog.class.getName();
+                logger = Logger.getLogger(logClassName);
+                logger.setLevel(Level.ALL);
+                logger.addHandler(fh);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private AppletLog() {
+    }
+
+    /**
+     * Log the exception to file.
+     * 
+     * @param e Exception that was thrown.
+     */
+    public synchronized static void log(Throwable e) {
+        if (enableLogging && logger != null) {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            PrintStream ps = new PrintStream(baos);
+            e.printStackTrace(ps);
+            logger.log(Level.FINE, baos.toString());
+        }
+    }
+}
diff -r ce755342e8e8 -r 98215ab000dd netx/net/sourceforge/jnlp/Log.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netx/net/sourceforge/jnlp/Log.java	Mon Jan 17 13:44:31 2011 -0500
@@ -0,0 +1,42 @@
+package net.sourceforge.jnlp;
+
+import java.io.File;
+
+import net.sourceforge.jnlp.config.DeploymentConfiguration;
+import net.sourceforge.jnlp.runtime.JNLPRuntime;
+
+/**
+ * This file provides the information required to do logging.
+ * 
+ * @author Andrew Su (asu at redhat.com, andrew.su at utoronto.ca)
+ * 
+ */
+abstract class Log {
+
+    // Directory where the logs are stored.
+    protected static String icedteaLogDir;
+
+    protected static boolean enableLogging = false;
+    protected static boolean enableTracing = false;
+
+    // Prepare for logging.
+    static {
+        DeploymentConfiguration config = JNLPRuntime.getConfiguration();
+
+        // Check whether logging and tracing is enabled.
+        enableLogging = Boolean.parseBoolean(config.getProperty(DeploymentConfiguration.KEY_ENABLE_LOGGING));
+        enableTracing = Boolean.parseBoolean(config.getProperty(DeploymentConfiguration.KEY_ENABLE_TRACING));
+
+        // Get log directory, create it if it doesn't exist. If unable to create and doesn't exist, don't log.
+        icedteaLogDir = config.getProperty(DeploymentConfiguration.KEY_USER_LOG_DIR);
+        if (icedteaLogDir != null) {
+            File f = new File(icedteaLogDir);
+            if (f.isDirectory() || f.mkdirs())
+                icedteaLogDir += File.separator;
+            else {
+                enableLogging = false;
+                enableTracing = false;
+            }
+        }
+    }
+}
diff -r ce755342e8e8 -r 98215ab000dd netx/net/sourceforge/jnlp/NetxPanel.java
--- a/netx/net/sourceforge/jnlp/NetxPanel.java	Fri Jan 14 11:14:46 2011 -0500
+++ b/netx/net/sourceforge/jnlp/NetxPanel.java	Mon Jan 17 13:44:31 2011 -0500
@@ -22,6 +22,7 @@
 
 package net.sourceforge.jnlp;
 
+import net.sourceforge.jnlp.AppletLog;
 import net.sourceforge.jnlp.runtime.AppThreadGroup;
 import net.sourceforge.jnlp.runtime.AppletInstance;
 import net.sourceforge.jnlp.runtime.JNLPRuntime;
@@ -68,6 +69,16 @@ public class NetxPanel extends AppletVie
         super.run();
     }
 
+    @Override
+    protected void showAppletException(Throwable t) {
+        /*
+         * Log any exceptions thrown while loading, initializing, starting,
+         * and stopping the applet. 
+         */
+        AppletLog.log(t);
+        super.showAppletException(t);
+    }
+    
     //Overriding to use Netx classloader. You might need to relax visibility
     //in sun.applet.AppletPanel for runLoader().
     protected void runLoader() {



More information about the distro-pkg-dev mailing list