    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.log4j;
    018
    019    import org.apache.log4j.spi.LoggingEvent;
    020    import org.apache.logging.log4j.core.util.Constants;
    021
    022    /**
    023     *
    024     */
    025    public abstract class Layout {
    026
    027        /** Note that the line.separator property can be looked up even by applets. */
    028        public static final int LINE_SEP_LEN = Constants.LINE_SEPARATOR.length();
    029
    030        /**
    031         * Implement this method to create your own layout format.
    032         * @param event The LoggingEvent.
    033         * @return The formatted LoggingEvent.
    034         */
    035        public abstract String format(LoggingEvent event);
    036
    037        /**
    038         * Returns the content type output by this layout. The base class
    039         * returns "text/plain".
    040         * @return the type of content rendered by the Layout.
    041         */
    042        public String getContentType() {
    043            return "text/plain";
    044        }
    045
    046        /**
    047         * Returns the header for the layout format. The base class returns
    048         * <code>null</code>.
    049         * @return The header.
    050         */
    051        public String getHeader() {
    052            return null;
    053        }
    054
    055        /**
    056         * Returns the footer for the layout format. The base class returns
    057         * <code>null</code>.
    058         * @return The footer.
    059         */
    060        public String getFooter() {
    061            return null;
    062        }
    063
    064
    065        /**
    066         * If the layout handles the throwable object contained within
    067         * {@link LoggingEvent}, then the layout should return
    068         * {@code false}. Otherwise, if the layout ignores throwable
    069         * object, then the layout should return {@code true}.
    070         * If ignoresThrowable is true, the appender is responsible for
    071         * rendering the throwable.
    072         * <p>
    073         * The <a href="/log4j/1.2/apidocs/org/apache/log4j/SimpleLayout.html">SimpleLayout</a>,
    074         * <a href="/log4j/1.2/apidocs/org/apache/log4j/TTCCLayout.html">TTCCLayout</a>,
    075         * <a href="/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html">PatternLayout</a>
    076         * all return {@code true}. The
    077         * <a href="/log4j/1.2/apidocs/org/apache/log4j/xml/XMLLayout.html">XMLLayout</a>
    078         * returns {@code false}.
    079         * </p>
    080         *
    081         * @return true if the Layout ignores Throwables.
    082         *
    083         * @since 0.8.4
    084         */
    085        public abstract boolean ignoresThrowable();
    086    }
    087