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