001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 * 
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.log4j.lf5;
019
020import org.apache.log4j.spi.ThrowableInformation;
021
022/**
023 * A <code>Log4JLogRecord</code> encapsulates
024 * the details of your log4j <code>LoggingEvent</code> in a format usable
025 * by the <code>LogBrokerMonitor</code>.
026 *
027 * @author Brent Sprecher
028 */
029
030// Contributed by ThoughtWorks Inc.
031
032public class Log4JLogRecord extends LogRecord {
033  //--------------------------------------------------------------------------
034  //   Constants:
035  //--------------------------------------------------------------------------
036
037  //--------------------------------------------------------------------------
038  //   Protected Variables:
039  //--------------------------------------------------------------------------
040
041  //--------------------------------------------------------------------------
042  //   Private Variables:
043  //--------------------------------------------------------------------------
044
045  //--------------------------------------------------------------------------
046  //   Constructors:
047  //--------------------------------------------------------------------------
048
049  /**
050   * Constructs an instance of a <code>Log4JLogRecord</code>.
051   */
052  public Log4JLogRecord() {
053  }
054
055  //--------------------------------------------------------------------------
056  //   Public Methods:
057  //--------------------------------------------------------------------------
058  /**
059   * Determines which <code>Priority</code> levels will
060   * be displayed in colored font when the <code>LogMonitorAppender</code>
061   * renders this log message. By default, messages will be colored
062   * red if they are of <code>Priority</code> ERROR or FATAL.
063   *
064   * @return true if the log level is ERROR or FATAL.
065   */
066  public boolean isSevereLevel() {
067    boolean isSevere = false;
068
069    if (LogLevel.ERROR.equals(getLevel()) ||
070        LogLevel.FATAL.equals(getLevel())) {
071      isSevere = true;
072    }
073
074    return isSevere;
075  }
076
077  /**
078   * Set stack trace information associated with this Log4JLogRecord.
079   * When this method is called, the stack trace in a
080   * String-based format is made
081   * available via the getThrownStackTrace() method.
082   *
083   * @param throwableInfo An org.apache.log4j.spi.ThrowableInformation to
084   * associate with this Log4JLogRecord.
085   * @see #getThrownStackTrace()
086   */
087  public void setThrownStackTrace(ThrowableInformation throwableInfo) {
088    String[] stackTraceArray = throwableInfo.getThrowableStrRep();
089
090    StringBuffer stackTrace = new StringBuffer();
091    String nextLine;
092
093    for (int i = 0; i < stackTraceArray.length; i++) {
094      nextLine = stackTraceArray[i] + "\n";
095      stackTrace.append(nextLine);
096    }
097
098    _thrownStackTrace = stackTrace.toString();
099  }
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