KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > LogRecord


1 package org.jzonic.jlo;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.io.StringWriter JavaDoc;
5 /**
6  *@author Andreas Mecky
7  *@author Terry Dye
8  *@created 9. März 2002
9  *@version 1.0
10  */

11 public class LogRecord {
12     
13     private String JavaDoc msg;
14     private long logdate;
15     private String JavaDoc loggername;
16     private String JavaDoc sourceClass = null;
17     private String JavaDoc sourceMethod = null;
18     private Throwable JavaDoc thrown;
19     private Target target;
20     private String JavaDoc configurationName;
21     private long elapsed;
22     private String JavaDoc ndc;
23     /**
24      * Constructor for the LogRecord object
25      *
26      *@param msg Description of the Parameter
27      */

28     public LogRecord(String JavaDoc msg) {
29         this(msg, null);
30     }
31
32
33     /**
34      * Constructor for the LogRecord object
35      *
36      *@param msg Description of the Parameter
37      *@param Target Description of the Parameter
38      */

39     public LogRecord(String JavaDoc msg, Target target) {
40         this.msg = msg;
41         this.target = target;
42         logdate = System.currentTimeMillis();
43
44     }
45
46
47     /**
48      * Get the logging message Target
49      *
50      *@return Target the current message Target
51      */

52     public Target getTarget() {
53         return target;
54     }
55
56
57     /**
58      * Get the source Logger name's
59      *
60      *@return loggername the name of the logger
61      */

62     public String JavaDoc getLoggerName() {
63         return loggername;
64     }
65
66
67     /**
68      * Get the "raw" log message, before localization or formatting.
69      *
70      *@return msg the raw message as string
71      */

72     public String JavaDoc getMessage() {
73         return msg;
74     }
75
76
77     /**
78      * Get event time in milliseconds since 1970.
79      *
80      *@return logdate the event time in milliseconds
81      */

82     public long getMillis() {
83         return logdate;
84     }
85
86
87     /**
88      * Get the name of the class that (allegedly) issued the logging request.
89      *
90      *@return
91      */

92     public String JavaDoc getSourceClassName() {
93         return sourceClass;
94     }
95
96
97     /**
98      * Get the name of the method that (allegedly) issued the logging request.
99      *
100      *@return
101      */

102     public String JavaDoc getSourceMethodName() {
103         return sourceMethod;
104     }
105
106
107     /**
108      * Get any throwable associated with the log record.
109      *
110      *@return
111      */

112     public Throwable JavaDoc getThrown() {
113         return thrown;
114     }
115
116
117     /**
118      * Set the logging message Target, for example Target.SEVERE.
119      *
120      *@param Target the Target of the logging request
121      */

122     public void setTarget(Target target) {
123         this.target = target;
124     }
125
126
127     /**
128      * Set the source Logger name.
129      *
130      *@param name the name of the logger
131      */

132     public void setLoggerName(String JavaDoc name) {
133         loggername = name;
134     }
135
136
137     /**
138      * Set the "raw" log message, before localization or formatting.
139      *
140      *@param message the message that should be logged
141      */

142     public void setMessage(String JavaDoc message) {
143         msg = message;
144     }
145
146
147     /**
148      * Set event time.
149      *
150      *@param millis the time in milliseconds
151      */

152     public void setMillis(long millis) {
153         logdate = millis;
154     }
155
156
157     /**
158      * Set the name of the class that (allegedly) issued the logging request.
159      *
160      *@param sourceClassName the name of the class
161      */

162     public void setSourceClassName(String JavaDoc sourceClassName) {
163         sourceClass = sourceClassName;
164     }
165
166
167     /**
168      * Set the name of the method that (allegedly) issued the logging request.
169      *
170      *@param sourceMethodName the name of the method
171      */

172     public void setSourceMethodName(String JavaDoc sourceMethodName) {
173         sourceMethod = sourceMethodName;
174     }
175
176
177     /**
178      * Set a throwable associated with the log event.
179      *
180      *@param thrown the exception
181      */

182     public void setThrown(Throwable JavaDoc thrown) {
183         this.thrown = thrown;
184     }
185     
186     public String JavaDoc getStackTrace() {
187         if ( thrown != null ) {
188             StringWriter JavaDoc sw = new StringWriter JavaDoc();
189             PrintWriter JavaDoc pw = new PrintWriter JavaDoc( sw );
190             thrown.printStackTrace( pw );
191             pw.close();
192             return sw.getBuffer().toString();
193         }
194         else {
195             return "";
196         }
197     }
198     
199     /** Getter for property configurationName.
200      * @return Value of property configurationName.
201      *
202      */

203     public String JavaDoc getConfigurationName() {
204         return configurationName;
205     }
206     
207     /** Setter for property configurationName.
208      * @param configurationName New value of property configurationName.
209      *
210      */

211     public void setConfigurationName(String JavaDoc configurationName) {
212         this.configurationName = configurationName;
213     }
214
215     public String JavaDoc getNDC() {
216         return ndc;
217     }
218
219     public void setNDC(String JavaDoc ndc) {
220         this.ndc = ndc;
221     }
222
223     public void setElapsed(long elapsed) {
224         this.elapsed = elapsed;
225     }
226
227     public long getElapsed() {
228         return elapsed;
229     }
230
231 }
232
Popular Tags