1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.core.layout; 18 19 import java.io.Serializable; 20 21 import org.apache.logging.log4j.Logger; 22 import org.apache.logging.log4j.core.Layout; 23 import org.apache.logging.log4j.status.StatusLogger; 24 25 /** 26 * Abstract base class for Layouts. 27 * 28 * @param <T> 29 * The Class that the Layout will format the LogEvent into. 30 */ 31 public abstract class AbstractLayout<T extends Serializable> implements Layout<T> { 32 33 /** 34 * Constructs a layout with an optional header and footer. 35 * 36 * @param header 37 * The header to include when the stream is opened. May be null. 38 * @param footer 39 * The footer to add when the stream is closed. May be null. 40 */ 41 public AbstractLayout(byte[] header, byte[] footer) { 42 super(); 43 this.header = header; 44 this.footer = footer; 45 } 46 47 /** 48 * Allow subclasses access to the status logger without creating another instance. 49 */ 50 protected static final Logger LOGGER = StatusLogger.getLogger(); 51 52 /** 53 * The header to include when the stream is opened. May be null. 54 */ 55 protected final byte[] header; 56 57 /** 58 * The footer to add when the stream is closed. May be null. 59 */ 60 protected final byte[] footer; 61 62 /** 63 * Returns the header, if one is available. 64 * 65 * @return A byte array containing the header. 66 */ 67 @Override 68 public byte[] getHeader() { 69 return header; 70 } 71 72 /** 73 * Returns the footer, if one is available. 74 * 75 * @return A byte array containing the footer. 76 */ 77 @Override 78 public byte[] getFooter() { 79 return footer; 80 } 81 }