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 018package org.apache.log4j; 019 020import org.apache.log4j.spi.OptionHandler; 021import org.apache.log4j.spi.LoggingEvent; 022 023/** 024 Extend this abstract class to create your own log layout format. 025 026 @author Ceki Gülcü 027 028*/ 029 030public abstract class Layout implements OptionHandler { 031 032 // Note that the line.separator property can be looked up even by 033 // applets. 034 public final static String LINE_SEP = System.getProperty("line.separator"); 035 public final static int LINE_SEP_LEN = LINE_SEP.length(); 036 037 038 /** 039 Implement this method to create your own layout format. 040 */ 041 abstract 042 public 043 String format(LoggingEvent event); 044 045 /** 046 Returns the content type output by this layout. The base class 047 returns "text/plain". 048 */ 049 public 050 String getContentType() { 051 return "text/plain"; 052 } 053 054 /** 055 Returns the header for the layout format. The base class returns 056 <code>null</code>. */ 057 public 058 String getHeader() { 059 return null; 060 } 061 062 /** 063 Returns the footer for the layout format. The base class returns 064 <code>null</code>. */ 065 public 066 String getFooter() { 067 return null; 068 } 069 070 071 072 /** 073 If the layout handles the throwable object contained within 074 {@link LoggingEvent}, then the layout should return 075 <code>false</code>. Otherwise, if the layout ignores throwable 076 object, then the layout should return <code>true</code>. 077 If ignoresThrowable is true, the appender is responsible for 078 rendering the throwable. 079 080 <p>The {@link SimpleLayout}, {@link TTCCLayout}, {@link 081 PatternLayout} all return <code>true</code>. The {@link 082 org.apache.log4j.xml.XMLLayout} returns <code>false</code>. 083 084 @since 0.8.4 */ 085 abstract 086 public 087 boolean ignoresThrowable(); 088 089}