1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support.log;
14
15 import java.awt.Component;
16
17 import javax.swing.JTabbedPane;
18
19 import org.apache.log4j.spi.LoggingEvent;
20
21 /***
22 * JTabbedPane that displays Log4J output in different tabs
23 *
24 * @author Ole.Matzura
25 */
26
27 public class Log4JMonitor extends JTabbedPane
28 {
29 private JLogList defaultLogArea;
30
31 public Log4JMonitor()
32 {
33 super( JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT );
34 }
35
36 public JLogList addLogArea( String title, String loggerName, boolean isDefault )
37 {
38 JLogList logArea = new JLogList( title );
39 logArea.addLogger( loggerName, !isDefault );
40 addTab( title, logArea);
41
42 if( isDefault )
43 defaultLogArea = logArea;
44
45 return logArea;
46 }
47
48 public void logEvent(Object msg)
49 {
50 if( msg instanceof LoggingEvent )
51 {
52 LoggingEvent event = (LoggingEvent) msg;
53 String loggerName = event.getLoggerName();
54
55 for( int c = 0; c < getTabCount(); c++ )
56 {
57 Component tabComponent = getComponentAt( c );
58 if( tabComponent instanceof JLogList )
59 {
60 JLogList logArea = (JLogList) tabComponent;
61 if( logArea.monitors( loggerName ))
62 {
63 logArea.addLine( msg );
64 }
65 }
66 }
67 }
68 else if( defaultLogArea != null )
69 {
70 defaultLogArea.addLine( msg );
71 }
72 }
73
74 public boolean hasLogArea(String loggerName)
75 {
76 for( int c = 0; c < getTabCount(); c++ )
77 {
78 Component tabComponent = getComponentAt( c );
79 if( tabComponent instanceof JLogList )
80 {
81 JLogList logArea = (JLogList) tabComponent;
82 if( logArea.monitors( loggerName ))
83 {
84 return true;
85 }
86 }
87 }
88
89 return false;
90 }
91 }