1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j;
19
20 import 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ülcü
32 @since version 0.7.0
33
34 <p>{@link PatternLayout} offers a much more powerful alternative.
35 */
36 public 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 }