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.LoggingEvent;
021
022/**
023   SimpleLayout consists of the level of the log statement,
024   followed by " - " and then the log message itself. For example,
025
026   <pre>
027           DEBUG - Hello world
028   </pre>
029
030   <p>
031   @author Ceki G&uuml;lc&uuml;
032   @since version 0.7.0
033
034   <p>{@link PatternLayout} offers a much more powerful alternative.
035*/
036public class SimpleLayout extends Layout {
037
038  StringBuffer sbuf = new StringBuffer(128);
039
040  public SimpleLayout() {
041  }
042
043  public
044  void activateOptions() {
045  }
046  
047  /**
048     Returns the log statement in a format consisting of the
049     <code>level</code>, followed by " - " and then the
050     <code>message</code>. For example, <pre> INFO - "A message"
051     </pre>
052
053     <p>The <code>category</code> parameter is ignored.
054     <p>
055     @return A byte array in SimpleLayout format.
056    */
057  public
058  String format(LoggingEvent event) {
059
060    sbuf.setLength(0);
061    sbuf.append(event.getLevel().toString());
062    sbuf.append(" - ");
063    sbuf.append(event.getRenderedMessage());
064    sbuf.append(LINE_SEP);
065    return sbuf.toString();
066  }
067
068/**
069     The SimpleLayout does not handle the throwable contained within
070     {@link LoggingEvent LoggingEvents}. Thus, it returns
071     <code>true</code>.
072
073     @since version 0.8.4 */
074  public
075  boolean ignoresThrowable() {
076    return true;
077  }
078}