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