/Users/lyon/j4p/src/classUtils/pack/util/sis/InfoEntry.java
|
1 package classUtils.pack.util.sis;
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.PrintStream;
5 import java.io.StringWriter;
6 import java.text.DateFormat;
7 import java.util.Date;
8
9 import classUtils.pack.util.IndentedPrintWriter;
10
11 /**
12 * A class to collect entries about the state of an MBean.
13 *
14 * @author cris
15 */
16 class InfoEntry {
17
18 private String description;
19 private Throwable e;
20 private Date timestamp;
21 private int level;
22
23 public InfoEntry(String description, int level) {
24 this(description, level, null);
25 }
26
27 public InfoEntry(String description, int level, Throwable e) {
28 this.timestamp=new Date();
29 this.description=description;
30 this.e=e;
31 }
32
33 public synchronized String toString() {
34 StringWriter sw=new StringWriter();
35 IndentedPrintWriter pw = new IndentedPrintWriter(sw);
36 pw.print("[");
37 pw.print(DateFormat.getDateTimeInstance().format(timestamp));
38 pw.print("] ");
39 pw.print(description);
40 if (e!=null) {
41 pw.println(" (stack trace follows):");
42 pw.println();
43 ByteArrayOutputStream os = new ByteArrayOutputStream();
44 e.printStackTrace(new PrintStream(os));
45 pw.incIndentation(5);
46 pw.print(os.toString());
47 pw.decIndentation(5);
48 }
49 return sw.toString();
50 }
51
52 /**
53 * Returns the level.
54 * @return int
55 */
56 public int getLevel() {
57 return level;
58 }
59
60 }
61