PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/apache-log4j-1.2.17/src/main/java/org/apache/log4j/SimpleLayout.java

#
Java | 78 lines | 23 code | 9 blank | 46 comment | 0 complexity | 84313ed29c45c96c6bbf5da0abfdf7c1 MD5 | raw file
Possible License(s): Apache-2.0
 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
18package org.apache.log4j;
19
20import org.apache.log4j.spi.LoggingEvent;
21
22/**
23   SimpleLayout consists of the level of the log statement,
24   followed by " - " and then the log message itself. For example,
25
26   <pre>
27           DEBUG - Hello world
28   </pre>
29
30   <p>
31   @author Ceki G&uuml;lc&uuml;
32   @since version 0.7.0
33
34   <p>{@link PatternLayout} offers a much more powerful alternative.
35*/
36public class SimpleLayout extends Layout {
37
38  StringBuffer sbuf = new StringBuffer(128);
39
40  public SimpleLayout() {
41  }
42
43  public
44  void activateOptions() {
45  }
46  
47  /**
48     Returns the log statement in a format consisting of the
49     <code>level</code>, followed by " - " and then the
50     <code>message</code>. For example, <pre> INFO - "A message"
51     </pre>
52
53     <p>The <code>category</code> parameter is ignored.
54     <p>
55     @return A byte array in SimpleLayout format.
56    */
57  public
58  String format(LoggingEvent event) {
59
60    sbuf.setLength(0);
61    sbuf.append(event.getLevel().toString());
62    sbuf.append(" - ");
63    sbuf.append(event.getRenderedMessage());
64    sbuf.append(LINE_SEP);
65    return sbuf.toString();
66  }
67
68/**
69     The SimpleLayout does not handle the throwable contained within
70     {@link LoggingEvent LoggingEvents}. Thus, it returns
71     <code>true</code>.
72
73     @since version 0.8.4 */
74  public
75  boolean ignoresThrowable() {
76    return true;
77  }
78}