1 /*
2 * Copyright 2005 Juan F. Codagnone <juam at users dot sourceforge dot net>
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 package ar.com.leak.iolsucker.view.common;
17
18 import javax.swing.JComponent;
19 import javax.swing.JTextArea;
20
21 import org.apache.log4j.AppenderSkeleton;
22 import org.apache.log4j.Layout;
23 import org.apache.log4j.spi.LoggingEvent;
24
25 /**
26 * Appender de log4j, que loguea el contenido en textarea.
27 *
28 * @author Juan F. Codagnone
29 * @since Mar 27, 2005
30 */
31 public class JTextAreaAppender extends AppenderSkeleton {
32 /** visual component */
33 private final JTextArea area = new JTextArea();
34 /** layout log4j layout to use (injected) */
35 private final Layout layout;
36 /** number of rows to show */
37 private static final int NUMBER_OF_ROWS = 10;
38 /**
39 * Crea el JTextAreaAppend.
40 * @param layout log4j layout to use
41 */
42 public JTextAreaAppender(final Layout layout) {
43 this.layout = layout;
44 area.setRows(NUMBER_OF_ROWS);
45 area.setEditable(false);
46 area.setLineWrap(true);
47 }
48
49 /**
50 * @return the visual component
51 */
52 public final JComponent asJComponent() {
53 return area;
54 }
55
56 /** @see AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent) */
57 protected final void append(final LoggingEvent event) {
58 area.append(layout.format(event));
59 }
60
61 /** @see org.apache.log4j.Appender#close() */
62 public final void close() {
63 // nothing to do
64 }
65
66 /** @see org.apache.log4j.Appender#requiresLayout() */
67 public final boolean requiresLayout() {
68 return false;
69 }
70 }
