diff options
Diffstat (limited to 'netx/net/sourceforge/jnlp/AppletLog.java')
-rw-r--r-- | netx/net/sourceforge/jnlp/AppletLog.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/netx/net/sourceforge/jnlp/AppletLog.java b/netx/net/sourceforge/jnlp/AppletLog.java new file mode 100644 index 0000000..bde8ede --- /dev/null +++ b/netx/net/sourceforge/jnlp/AppletLog.java @@ -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 ([email protected], [email protected]) + * + */ +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()); + } + } +} |