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.pattern;
019
020import org.apache.log4j.spi.LoggingEvent;
021
022
023/**
024 * LoggingEventPatternConverter is a base class for pattern converters
025 * that can format information from instances of LoggingEvent.
026 *
027 * @author Curt Arnold
028 *
029 */
030public abstract class LoggingEventPatternConverter extends PatternConverter {
031  /**
032   * Constructs an instance of LoggingEventPatternConverter.
033   * @param name name of converter.
034   * @param style CSS style for output.
035   */
036  protected LoggingEventPatternConverter(
037    final String name, final String style) {
038    super(name, style);
039  }
040
041  /**
042   * Formats an event into a string buffer.
043   * @param event event to format, may not be null.
044   * @param toAppendTo string buffer to which the formatted event will be appended.  May not be null.
045   */
046  public abstract void format(
047    final LoggingEvent event, final StringBuffer toAppendTo);
048
049  /**
050   * {@inheritDoc}
051   */
052  public void format(final Object obj, final StringBuffer output) {
053    if (obj instanceof LoggingEvent) {
054      format((LoggingEvent) obj, output);
055    }
056  }
057
058  /**
059   * Normally pattern converters are not meant to handle Exceptions although
060   * few pattern converters might.
061   *
062   * By examining the return values for this method, the containing layout will
063   * determine whether it handles throwables or not.
064
065   * @return true if this PatternConverter handles throwables
066   */
067  public boolean handlesThrowable() {
068    return false;
069  }
070}