    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.layout;
    018
    019    import java.io.Serializable;
    020    import java.util.HashMap;
    021    import java.util.Map;
    022
    023    import org.apache.logging.log4j.Logger;
    024    import org.apache.logging.log4j.core.Layout;
    025    import org.apache.logging.log4j.status.StatusLogger;
    026
    027    /**
    028     * Abstract base class for Layouts.
    029     *
    030     * @param <T>
    031     *        The Class that the Layout will format the LogEvent into.
    032     */
    033    public abstract class AbstractLayout<T extends Serializable> implements Layout<T>, Serializable {
    034
    035        private static final long serialVersionUID = 1L;
    036
    037        /**
    038         * Allow subclasses access to the status logger without creating another instance.
    039         */
    040        protected static final Logger LOGGER = StatusLogger.getLogger();
    041
    042        /**
    043         * The header to include when the stream is opened. May be null.
    044         */
    045        protected final byte[] header;
    046
    047        /**
    048         * The footer to add when the stream is closed. May be null.
    049         */
    050        protected final byte[] footer;
    051
    052        /**
    053         * Constructs a layout with an optional header and footer.
    054         *
    055         * @param header
    056         *        The header to include when the stream is opened. May be null.
    057         * @param footer
    058         *        The footer to add when the stream is closed. May be null.
    059         */
    060        public AbstractLayout(final byte[] header, final byte[] footer) {
    061            super();
    062            this.header = header;
    063            this.footer = footer;
    064        }
    065
    066        @Override
    067        public Map<String, String> getContentFormat() {
    068            return new HashMap<String, String>();
    069        }
    070
    071        /**
    072         * Returns the footer, if one is available.
    073         *
    074         * @return A byte array containing the footer.
    075         */
    076        @Override
    077        public byte[] getFooter() {
    078            return footer;
    079        }
    080
    081        /**
    082         * Returns the header, if one is available.
    083         *
    084         * @return A byte array containing the header.
    085         */
    086        @Override
    087        public byte[] getHeader() {
    088            return header;
    089        }
    090    }