KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > log > LogEvent


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package org.jivesoftware.util.log;
10
11 import java.io.ObjectStreamException JavaDoc;
12 import java.io.Serializable JavaDoc;
13
14 /**
15  * This class encapsulates each individual log event.
16  * LogEvents usually originate at a Logger and are routed
17  * to LogTargets.
18  *
19  * @author <a HREF="mailto:peter@apache.org">Peter Donald</a>
20  */

21 public final class LogEvent
22         implements Serializable JavaDoc {
23     //A Constant used when retrieving time relative to start of applicaiton start
24
private final static long START_TIME = System.currentTimeMillis();
25
26     ///The category that this LogEvent concerns. (Must not be null)
27
private String JavaDoc m_category;
28
29     ///The message to be logged. (Must not be null)
30
private String JavaDoc m_message;
31
32     ///The exception that caused LogEvent if any. (May be null)
33
private Throwable JavaDoc m_throwable;
34
35     ///The time in millis that LogEvent occurred
36
private long m_time;
37
38     ///The priority of LogEvent. (Must not be null)
39
private Priority m_priority;
40
41     ///The context map associated with LogEvent. (May be null).
42
private ContextMap m_contextMap;
43
44     /**
45      * Get Priority for LogEvent.
46      *
47      * @return the LogEvent Priority
48      */

49     public final Priority getPriority() {
50         return m_priority;
51     }
52
53     /**
54      * Set the priority of LogEvent.
55      *
56      * @param priority the new LogEvent priority
57      */

58     public final void setPriority(final Priority priority) {
59         m_priority = priority;
60     }
61
62     /**
63      * Get ContextMap associated with LogEvent
64      *
65      * @return the ContextMap
66      */

67     public final ContextMap getContextMap() {
68         return m_contextMap;
69     }
70
71     /**
72      * Set the ContextMap for this LogEvent.
73      *
74      * @param contextMap the context map
75      */

76     public final void setContextMap(final ContextMap contextMap) {
77         m_contextMap = contextMap;
78     }
79
80 // /**
81
// * Get ContextStack associated with LogEvent
82
// *
83
// * @return the ContextStack
84
// * @deprecated ContextStack has been deprecated and thus so has this method
85
// */
86
// public final ContextStack getContextStack()
87
// {
88
// return m_contextStack;
89
// }
90

91 // /**
92
// * Set the ContextStack for this LogEvent.
93
// * Note that if this LogEvent ever changes threads, the
94
// * ContextStack must be cloned.
95
// *
96
// * @param contextStack the context stack
97
// * @deprecated ContextStack has been deprecated and thus so has this method
98
// */
99
// public final void setContextStack( final ContextStack contextStack )
100
// {
101
// m_contextStack = contextStack;
102
// }
103

104     /**
105      * Get the category that LogEvent relates to.
106      *
107      * @return the name of category
108      */

109     public final String JavaDoc getCategory() {
110         return m_category;
111     }
112
113     /**
114      * Get the message associated with event.
115      *
116      * @return the message
117      */

118     public final String JavaDoc getMessage() {
119         return m_message;
120     }
121
122     /**
123      * Get throwabe instance associated with event.
124      *
125      * @return the Throwable
126      */

127     public final Throwable JavaDoc getThrowable() {
128         return m_throwable;
129     }
130
131     /**
132      * Get the absolute time of the log event.
133      *
134      * @return the absolute time
135      */

136     public final long getTime() {
137         return m_time;
138     }
139
140     /**
141      * Get the time of the log event relative to start of application.
142      *
143      * @return the time
144      */

145     public final long getRelativeTime() {
146         return m_time - START_TIME;
147     }
148
149     /**
150      * Set the LogEvent category.
151      *
152      * @param category the category
153      */

154     public final void setCategory(final String JavaDoc category) {
155         m_category = category;
156     }
157
158     /**
159      * Set the message for LogEvent.
160      *
161      * @param message the message
162      */

163     public final void setMessage(final String JavaDoc message) {
164         m_message = message;
165     }
166
167     /**
168      * Set the throwable for LogEvent.
169      *
170      * @param throwable the instance of Throwable
171      */

172     public final void setThrowable(final Throwable JavaDoc throwable) {
173         m_throwable = throwable;
174     }
175
176     /**
177      * Set the absolute time of LogEvent.
178      *
179      * @param time the time
180      */

181     public final void setTime(final long time) {
182         m_time = time;
183     }
184
185
186     /**
187      * Helper method that replaces deserialized priority with correct singleton.
188      *
189      * @return the singleton version of object
190      * @throws ObjectStreamException if an error occurs
191      */

192     private Object JavaDoc readResolve()
193             throws ObjectStreamException JavaDoc {
194         if (null == m_category) m_category = "";
195         if (null == m_message) m_message = "";
196
197         String JavaDoc priorityName = "";
198         if (null != m_priority) {
199             priorityName = m_priority.getName();
200         }
201
202         m_priority = Priority.getPriorityForName(priorityName);
203
204         return this;
205     }
206 }
207
Popular Tags