1 package org.lsst.ccs.bus;
2
3 import java.io.Serializable;
4
5 /**
6 * Logging event to be sent on logging bus.
7 * Data is independent of Logging implementation and should be sent across
8 * the buses to agent that do not have necessarily the same classes.
9 * (for this reason we do not send objects of any kind including Throwables)
10 *
11 * @ImplNote
12 * we create our own object with fields we control
13 * with an API that enables us to send String information instead of Throwable
14 * @author aubourg
15 */
16
17 // TODO check metadata, what kind of object, and check with log4j interface that
18 // can accept Object messages
19
20 public class LogEvent extends BusMessage implements Serializable {
21
22 private static final long serialVersionUID = -4194787513329636909L;
23
24 private final String threadName;
25
26 private final String loggerName;
27
28 private final String sourceName;
29
30 private final String formattedDetails;
31
32 private final String level;
33
34 /*
35 // TODO Able to convert to/from log4j, and other systems should be possible
36 public LogEvent(Object o) {
37 obj = o;
38
39 // TBD move log4j specific stuff back to the log4j bridge?
40 if (o instanceof LoggingEvent) {
41 LoggingEvent l4evt = (LoggingEvent) o;
42 timeStamp = l4evt.timeStamp;
43 summary = l4evt.getMessage().toString();
44 Level l4jLev = l4evt.getLevel();
45 if (l4jLev.equals(Level.DEBUG))
46 detailLevel = DetailLevel.FINEST;
47 else if (l4jLev.equals(Level.INFO))
48 detailLevel = DetailLevel.INFO;
49 else if (l4jLev.equals(Level.WARN))
50 detailLevel = DetailLevel.WARNING;
51 else if (l4jLev.equals(Level.ERROR))
52 detailLevel = DetailLevel.SEVERE;
53 else if (l5jLev.equals(Level.FATAL))
54 detailLevel = DetailLevel.SEVERE;
55 else
56 detailLevel = DetailLevel.FINE;
57 }
58 }
59
60 */
61
62 /**
63 *
64 * @param threadName the name of the thread (important since Commands have a special name)
65 * @param loggerName the name of the logger which issued the log
66 * @param sourceName concatenation of the form ClassName#methodName
67 * @param formattedDetails a formatted String that represents the Log record (can be text or xml)
68 * it is dependent on the <TT>Formatter</TT> of the Handler.
69 * @param level A string representing the Level
70 */
71 public LogEvent(String threadName, String loggerName, String sourceName, String formattedDetails, String level) {
72 this.threadName = threadName;
73 this.loggerName = loggerName;
74 this.sourceName = sourceName;
75 this.formattedDetails = formattedDetails;
76 this.level = level;
77 }
78
79 @Override
80 public String getMessageType() {
81 return "lsst.log";
82 }
83
84
85
86 public String getThreadName() {
87 return threadName;
88 }
89
90 public String getLoggerName() {
91 return loggerName;
92 }
93
94 public String getSourceName() {
95 return sourceName;
96 }
97
98 public String getFormattedDetails() {
99 return formattedDetails;
100 }
101
102 public String getLevel() {
103 return level;
104 }
105
106
107 /**
108 * returns the "formatted details"
109 * @return
110 */
111 @Override
112 public String toString() {
113 return formattedDetails;
114 }
115 }
116
117
118
119