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 org.apache.logging.log4j.Logger; 020 import org.apache.logging.log4j.core.Layout; 021 import org.apache.logging.log4j.status.StatusLogger; 022 023 import java.io.Serializable; 024 025 /** 026 * Abstract base class for Layouts. 027 * @param <T> The Class that the Layout will format the LogEvent into. 028 */ 029 public abstract class AbstractLayout<T extends Serializable> implements Layout<T> { 030 /** 031 * Allow subclasses access to the status logger without creating another instance. 032 */ 033 protected static final Logger LOGGER = StatusLogger.getLogger(); 034 /** 035 * The header to include when the stream is opened. May be null. 036 */ 037 protected byte[] header; 038 /** 039 * The footer to add when the stream is closed. May be null. 040 */ 041 protected byte[] footer; 042 043 /** 044 * Returns the header, if one is available. 045 * @return A byte array containing the header. 046 */ 047 @Override 048 public byte[] getHeader() { 049 return header; 050 } 051 052 /** 053 * Set the header. 054 * @param header The header. 055 */ 056 public void setHeader(final byte[] header) { 057 this.header = header; 058 } 059 060 /** 061 * Returns the footer, if one is available. 062 * @return A byte array containing the footer. 063 */ 064 @Override 065 public byte[] getFooter() { 066 return footer; 067 } 068 069 /** 070 * Set the footer. 071 * @param footer The footer. 072 */ 073 public void setFooter(final byte[] footer) { 074 this.footer = footer; 075 } 076 }