View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.log4j.lf5;
19  
20  import org.apache.log4j.spi.ThrowableInformation;
21  
22  /**
23   * A <code>Log4JLogRecord</code> encapsulates
24   * the details of your log4j <code>LoggingEvent</code> in a format usable
25   * by the <code>LogBrokerMonitor</code>.
26   *
27   * @author Brent Sprecher
28   */
29  
30  // Contributed by ThoughtWorks Inc.
31  
32  public class Log4JLogRecord extends LogRecord {
33    //--------------------------------------------------------------------------
34    //   Constants:
35    //--------------------------------------------------------------------------
36  
37    //--------------------------------------------------------------------------
38    //   Protected Variables:
39    //--------------------------------------------------------------------------
40  
41    //--------------------------------------------------------------------------
42    //   Private Variables:
43    //--------------------------------------------------------------------------
44  
45    //--------------------------------------------------------------------------
46    //   Constructors:
47    //--------------------------------------------------------------------------
48  
49    /**
50     * Constructs an instance of a <code>Log4JLogRecord</code>.
51     */
52    public Log4JLogRecord() {
53    }
54  
55    //--------------------------------------------------------------------------
56    //   Public Methods:
57    //--------------------------------------------------------------------------
58    /**
59     * Determines which <code>Priority</code> levels will
60     * be displayed in colored font when the <code>LogMonitorAppender</code>
61     * renders this log message. By default, messages will be colored
62     * red if they are of <code>Priority</code> ERROR or FATAL.
63     *
64     * @return true if the log level is ERROR or FATAL.
65     */
66    public boolean isSevereLevel() {
67      boolean isSevere = false;
68  
69      if (LogLevel.ERROR.equals(getLevel()) ||
70          LogLevel.FATAL.equals(getLevel())) {
71        isSevere = true;
72      }
73  
74      return isSevere;
75    }
76  
77    /**
78     * Set stack trace information associated with this Log4JLogRecord.
79     * When this method is called, the stack trace in a
80     * String-based format is made
81     * available via the getThrownStackTrace() method.
82     *
83     * @param throwableInfo An org.apache.log4j.spi.ThrowableInformation to
84     * associate with this Log4JLogRecord.
85     * @see #getThrownStackTrace()
86     */
87    public void setThrownStackTrace(ThrowableInformation throwableInfo) {
88      String[] stackTraceArray = throwableInfo.getThrowableStrRep();
89  
90      StringBuffer stackTrace = new StringBuffer();
91      String nextLine;
92  
93      for (int i = 0; i < stackTraceArray.length; i++) {
94        nextLine = stackTraceArray[i] + "\n";
95        stackTrace.append(nextLine);
96      }
97  
98      _thrownStackTrace = stackTrace.toString();
99    }
100 
101   //--------------------------------------------------------------------------
102   //   Protected Methods:
103   //--------------------------------------------------------------------------
104 
105   //--------------------------------------------------------------------------
106   //   Private Methods:
107   //--------------------------------------------------------------------------
108 
109   //--------------------------------------------------------------------------
110   //   Nested Top-Level Classes or Interfaces:
111   //--------------------------------------------------------------------------
112 
113 }
114 
115 
116