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