blob: 9c178f8253b03b15f947ff478b42c870d5c33aad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package net.sourceforge.jnlp;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;
import net.sourceforge.jnlp.util.FileUtils;
/**
* This class writes log information to file.
*
* @author Andrew Su (asu@redhat.com, andrew.su@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";
FileUtils.createRestrictedFile(new File(fn), true);
FileHandler fh = new FileHandler(fn, false);
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());
}
}
}
|