KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > SimpleLayout


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.log4j;
18
19 import org.apache.log4j.spi.LoggingEvent;
20
21 /**
22    SimpleLayout consists of the level of the log statement,
23    followed by " - " and then the log message itself. For example,
24
25    <pre>
26            DEBUG - Hello world
27    </pre>
28
29    <p>
30    @author Ceki G&uuml;lc&uuml;
31    @since version 0.7.0
32
33    <p>{@link PatternLayout} offers a much more powerful alternative.
34 */

35 public class SimpleLayout extends Layout {
36
37   StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc(128);
38
39   public SimpleLayout() {
40   }
41
42   public
43   void activateOptions() {
44   }
45   
46   /**
47      Returns the log statement in a format consisting of the
48      <code>level</code>, followed by " - " and then the
49      <code>message</code>. For example, <pre> INFO - "A message"
50      </pre>
51
52      <p>The <code>category</code> parameter is ignored.
53      <p>
54      @return A byte array in SimpleLayout format.
55     */

56   public
57   String JavaDoc format(LoggingEvent event) {
58
59     sbuf.setLength(0);
60     sbuf.append(event.getLevel().toString());
61     sbuf.append(" - ");
62     sbuf.append(event.getRenderedMessage());
63     sbuf.append(LINE_SEP);
64     return sbuf.toString();
65   }
66
67 /**
68      The SimpleLayout does not handle the throwable contained within
69      {@link LoggingEvent LoggingEvents}. Thus, it returns
70      <code>true</code>.
71
72      @since version 0.8.4 */

73   public
74   boolean ignoresThrowable() {
75     return true;
76   }
77 }
78
Popular Tags