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; 018 019 import java.io.Serializable; 020 021 /** 022 * Lays out a {@linkplain LogEvent} in different formats. 023 * The formats are: byte[], or an implementor of {@linkplain Serializable}, like {@code byte[]}, 024 * String, and LogEvent. 025 * 026 * @doubt There is still a need for a character-based layout for character based event sinks (databases, etc). Would introduce an 027 * EventEncoder, EventRenderer or something similar for the logging event to byte encoding. (RG) A layout can be configured with a 028 * Charset and then Strings can be converted to byte arrays. OTOH, it isn't possible to write byte arrays as character streams. 029 * @param <T> 030 * The Object type that will be returned on the {@link #toSerializable(LogEvent)} call. 031 */ 032 public interface Layout<T extends Serializable> { 033 /** 034 * Returns the format for the layout format. 035 * @return The footer. 036 * @doubt the concept of header and footer is not universal, should not be on the base interface. 037 * (RG) I agree with this. 038 */ 039 byte[] getFooter(); 040 041 /** 042 * Returns the header for the layout format. 043 * @return The header. 044 * @doubt the concept of header and footer is not universal, should not be on the base interface. 045 * (RG) I agree with this. 046 */ 047 byte[] getHeader(); 048 049 /** 050 * Formats the event suitable for display. 051 * 052 * @param event The Logging Event. 053 * @return The formatted event. 054 * @doubt Likely better to write to a OutputStream instead of return a byte[]. (RG) That limits how the 055 * Appender can use the Layout. For example, it might concatenate information in front or behind the 056 * data and then write it all to the OutputStream in one call. 057 */ 058 byte[] toByteArray(LogEvent event); 059 060 /** 061 * Formats the event as an Object that can be serialized. 062 * 063 * @param event The Logging Event. 064 * @return The formatted event. 065 */ 066 T toSerializable(LogEvent event); 067 068 069 }