01: package dalma.impl;
02:
03: import java.util.Date;
04: import java.util.logging.LogRecord;
05: import java.util.logging.Level;
06:
07: /**
08: * Persistence form of {@link LogRecord}.
09: *
10: * @author Kohsuke Kawaguchi
11: */
12: public class XmlLogRecord {
13: public String level;
14: public String loggerName;
15: public String message;
16: public Date time;
17: public String[] parameters;
18: public long sequenceNumber;
19: public String sourceClassName;
20: public String sourceMethodName;
21: public int threadId;
22: public RecordableException thrown;
23:
24: public XmlLogRecord() {
25: }
26:
27: public XmlLogRecord(LogRecord lr) {
28: set(lr);
29: }
30:
31: public void set(LogRecord lr) {
32: this .level = lr.getLevel().getName();
33: this .loggerName = lr.getLoggerName();
34: this .message = lr.getMessage();
35: this .time = new Date(lr.getMillis());
36: Object[] params = lr.getParameters();
37: if (params != null) {
38: String[] r = new String[params.length];
39: for (int i = 0; i < r.length; i++) {
40: if (params[i] != null)
41: r[i] = params[i].toString();
42: else
43: r[i] = null;
44: }
45: this .parameters = r;
46: }
47: this .sequenceNumber = lr.getSequenceNumber();
48: this .sourceClassName = lr.getSourceClassName();
49: this .sourceMethodName = lr.getSourceMethodName();
50: this .threadId = lr.getThreadID();
51: this .thrown = RecordableException.create(lr.getThrown());
52: }
53:
54: public LogRecord get() {
55: LogRecord r = new LogRecord(Level.parse(level), message);
56: r.setLoggerName(loggerName);
57: r.setParameters(parameters);
58: r.setSequenceNumber(sequenceNumber);
59: r.setSourceClassName(sourceClassName);
60: r.setSourceMethodName(sourceMethodName);
61: r.setThreadID(threadId);
62: r.setThrown(thrown);
63: if (time != null)
64: r.setMillis(time.getTime());
65: return r;
66: }
67: }
|