root/trunk/src/java/org/jcoderz/commons/LogEvent.java

Revision 1492, 5.0 kB (checked in by amandel, 3 years ago)

Add new way to get Loggable dump with nested parameters.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 *
4 * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *    * Redistributions of source code must retain the above copyright
11 *      notice, this list of conditions and the following disclaimer.
12 *    * Redistributions in binary form must reproduce the above
13 *      copyright notice, this list of conditions and the following
14 *      disclaimer in the documentation and/or other materials
15 *      provided with the distribution.
16 *    * Neither the name of the jCoderZ.org Project nor the names of
17 *      its contributors may be used to endorse or promote products
18 *      derived from this software without specific prior written
19 *      permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33package org.jcoderz.commons;
34
35
36import java.io.Serializable;
37import java.util.List;
38import java.util.Set;
39
40
41/**
42 * This is the Base class for log events.
43 *
44 * <p>The base class of this LogEvent is Throwable but instances
45 * of this class are not expected to be thrown.</p>
46 *
47 * <p>Most functionality is implemented and documented by the
48 * {@link org.jcoderz.commons.LoggableImpl} which is used a member of
49 * objects of this class.</p>
50 *
51 * @see org.jcoderz.commons
52 * @author Andreas Mandel
53 */
54public class LogEvent
55      extends Throwable
56      implements Loggable
57{
58   static final long serialVersionUID = 2L;
59
60   /** The loggable implementation. */
61   private final LoggableImpl mLoggable;
62
63   /**
64    * Constructor getting an log message info.
65    *
66    * @param messageInfo the log message info for this exception
67    */
68   public LogEvent (LogMessageInfo messageInfo)
69   {
70      super(messageInfo.getSymbol());
71      mLoggable = new LoggableImpl(this, messageInfo);
72   }
73
74   /**
75    * Constructor getting an log message info and a root exception.
76    *
77    * @param messageInfo the log message info for this exception
78    * @param cause the problem that caused this exception to be thrown
79    */
80   public LogEvent (LogMessageInfo messageInfo, Throwable cause)
81   {
82      super(messageInfo.getSymbol(), cause);
83      mLoggable = new LoggableImpl(this, messageInfo, cause);
84   }
85
86   /** {@inheritDoc} */
87   public Throwable initCause (Throwable cause)
88   {
89      super.initCause(cause);
90      mLoggable.initCause(cause);
91      return this;
92   }
93
94   /** {@inheritDoc} */
95   public final void addParameter (String name, Serializable value)
96   {
97      mLoggable.addParameter(name, value);
98   }
99
100   /** {@inheritDoc} */
101   public String getInstanceId ()
102   {
103      return mLoggable.getInstanceId();
104   }
105
106   /** {@inheritDoc} */
107   public final String getMessage ()
108   {
109      return mLoggable.getMessage();
110   }
111
112   /** {@inheritDoc} */
113   public final void log ()
114   {
115      mLoggable.log();
116   }
117
118   /** {@inheritDoc} */
119   public Throwable getCause ()
120   {
121      return mLoggable.getCause();
122   }
123
124   /** {@inheritDoc} */
125   public long getEventTime ()
126   {
127      return mLoggable.getEventTime();
128   }
129
130   /** {@inheritDoc} */
131   public LogMessageInfo getLogMessageInfo ()
132   {
133      return mLoggable.getLogMessageInfo();
134   }
135
136   /** {@inheritDoc} */
137   public String getNodeId ()
138   {
139      return mLoggable.getNodeId();
140   }
141
142   /** {@inheritDoc} */
143   public List getParameter (String name)
144   {
145      return mLoggable.getParameter(name);
146   }
147
148   /** {@inheritDoc} */
149   public Set getParameterNames ()
150   {
151      return mLoggable.getParameterNames();
152   }
153
154   /** {@inheritDoc} */
155   public long getThreadId ()
156   {
157      return mLoggable.getThreadId();
158   }
159
160   /** {@inheritDoc} */
161   public String getTrackingNumber ()
162   {
163      return mLoggable.getTrackingNumber();
164   }
165
166   /** {@inheritDoc} */
167   public String getSourceClass ()
168   {
169      return mLoggable.getSourceClass();
170   }
171
172   /** {@inheritDoc} */
173   public String getSourceMethod ()
174   {
175      return mLoggable.getSourceMethod();
176   }
177
178   /** {@inheritDoc} */
179   public String getThreadName ()
180   {
181       return mLoggable.getThreadName();
182   }
183
184   /** {@inheritDoc} */
185   public String toString ()
186   {
187      return mLoggable.toString();
188   }
189
190   /** {@inheritDoc} */
191   public String toDetailedString ()
192   {
193      return mLoggable.toDetailedString();
194   }
195
196
197   LoggableImpl getExceptionImpl ()
198   {
199      return mLoggable;
200   }
201}
Note: See TracBrowser for help on using the browser.