KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > Log4JLogRecord


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j.lf5;
18
19 import org.apache.log4j.spi.ThrowableInformation;
20
21 /**
22  * A <code>Log4JLogRecord</code> encapsulates
23  * the details of your log4j <code>LoggingEvent</code> in a format usable
24  * by the <code>LogBrokerMonitor</code>.
25  *
26  * @author Brent Sprecher
27  */

28
29 // Contributed by ThoughtWorks Inc.
30

31 public class Log4JLogRecord extends LogRecord {
32   //--------------------------------------------------------------------------
33
// Constants:
34
//--------------------------------------------------------------------------
35

36   //--------------------------------------------------------------------------
37
// Protected Variables:
38
//--------------------------------------------------------------------------
39

40   //--------------------------------------------------------------------------
41
// Private Variables:
42
//--------------------------------------------------------------------------
43

44   //--------------------------------------------------------------------------
45
// Constructors:
46
//--------------------------------------------------------------------------
47

48   /**
49    * Constructs an instance of a <code>Log4JLogRecord</code>.
50    */

51   public Log4JLogRecord() {
52   }
53
54   //--------------------------------------------------------------------------
55
// Public Methods:
56
//--------------------------------------------------------------------------
57
/**
58    * Determines which <code>Priority</code> levels will
59    * be displayed in colored font when the <code>LogMonitorAppender</code>
60    * renders this log message. By default, messages will be colored
61    * red if they are of <code>Priority</code> ERROR or FATAL.
62    *
63    * @return true if the log level is ERROR or FATAL.
64    */

65   public boolean isSevereLevel() {
66     boolean isSevere = false;
67
68     if (LogLevel.ERROR.equals(getLevel()) ||
69         LogLevel.FATAL.equals(getLevel())) {
70       isSevere = true;
71     }
72
73     return isSevere;
74   }
75
76   /**
77    * Set stack trace information associated with this Log4JLogRecord.
78    * When this method is called, the stack trace in a
79    * String-based format is made
80    * available via the getThrownStackTrace() method.
81    *
82    * @param throwableInfo An org.apache.log4j.spi.ThrowableInformation to
83    * associate with this Log4JLogRecord.
84    * @see #getThrownStackTrace()
85    */

86   public void setThrownStackTrace(ThrowableInformation throwableInfo) {
87     String JavaDoc[] stackTraceArray = throwableInfo.getThrowableStrRep();
88
89     StringBuffer JavaDoc stackTrace = new StringBuffer JavaDoc();
90     String JavaDoc nextLine;
91
92     for (int i = 0; i < stackTraceArray.length; i++) {
93       nextLine = stackTraceArray[i] + "\n";
94       stackTrace.append(nextLine);
95     }
96
97     _thrownStackTrace = stackTrace.toString();
98   }
99
100   //--------------------------------------------------------------------------
101
// Protected Methods:
102
//--------------------------------------------------------------------------
103

104   //--------------------------------------------------------------------------
105
// Private Methods:
106
//--------------------------------------------------------------------------
107

108   //--------------------------------------------------------------------------
109
// Nested Top-Level Classes or Interfaces:
110
//--------------------------------------------------------------------------
111

112 }
113
114
115
116
Popular Tags