oburn 2003/03/10 02:24:13
Modified: src/java/org/apache/log4j/chainsaw XMLFileHandler.java
RecentFilesMenu.java MyTableModel.java
MyTableColumnModel.java Main.java
LoggingReceiver.java LoadXMLAction.java
DetailPanel.java
Added: src/java/org/apache/log4j/chainsaw log4j.xml Start.java
Log4JConfigurationFinder.java EventDetailSink.java
ChainsawAppender.java
Log:
Apply excellent patch from Paul Smith. There are numerous checkstyle errors
that will need to be fixed at some stage. Also wonder what the best strategy
is for the log4j.xml file. Note, I really like the approach for finder
strategies.
Revision Changes Path
1.7 +4 -4
jakarta-log4j/src/java/org/apache/log4j/chainsaw/XMLFileHandler.java
Index: XMLFileHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/XMLFileHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLFileHandler.java 25 Feb 2003 12:49:14 -0000 1.6
+++ XMLFileHandler.java 10 Mar 2003 10:24:12 -0000 1.7
@@ -86,7 +86,7 @@
private static final String TAG_LOCATION_INFO = "log4j:locationInfo";
/** where to put the events **/
- private final MyTableModel mModel;
+ private final EventDetailSink mEventSink;
/** the number of events in the document **/
private int mNumEvents;
@@ -114,8 +114,8 @@
*
* @param aModel where to add the events
*/
- XMLFileHandler(MyTableModel aModel) {
- mModel = aModel;
+ XMLFileHandler(EventDetailSink aEventSink) {
+ mEventSink = aEventSink;
}
/** @see DefaultHandler **/
@@ -200,7 +200,7 @@
/** Add an event to the model **/
private void addEvent() {
- mModel.addEvent(new EventDetails(mTimeStamp,
+ mEventSink.addEvent(new EventDetails(mTimeStamp,
mPriority,
mCategoryName,
mNDC,
1.2 +4 -4
jakarta-log4j/src/java/org/apache/log4j/chainsaw/RecentFilesMenu.java
Index: RecentFilesMenu.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/RecentFilesMenu.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RecentFilesMenu.java 25 Feb 2003 12:51:16 -0000 1.1
+++ RecentFilesMenu.java 10 Mar 2003 10:24:12 -0000 1.2
@@ -68,7 +68,7 @@
public class RecentFilesMenu extends JMenu {
/** Logger for class */
private static final Logger LOG = Logger.getLogger(RecentFilesMenu.class);
- private final MyTableModel mModel;
+ private final EventDetailSink eventSink;
private final XMLFileHandler mHandler;
/**
@@ -77,10 +77,10 @@
*
* @param model the table model
*/
- public RecentFilesMenu(MyTableModel model) {
+ public RecentFilesMenu(EventDetailSink eventSink) {
super("Recent Files");
- mModel = model;
- mHandler = new XMLFileHandler(model);
+ this.eventSink = eventSink;
+ mHandler = new XMLFileHandler(eventSink);
}
/**
1.5 +50 -6
jakarta-log4j/src/java/org/apache/log4j/chainsaw/MyTableModel.java
Index: MyTableModel.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/MyTableModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MyTableModel.java 24 Apr 2002 14:41:47 -0000 1.4
+++ MyTableModel.java 10 Mar 2003 10:24:12 -0000 1.5
@@ -1,9 +1,51 @@
/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
*
- * This software is published under the terms of the Apache Software
- * License version 1.1, a copy of which has been included with this
- * distribution in the LICENSE.txt file. */
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
package org.apache.log4j.chainsaw;
import java.text.DateFormat;
@@ -14,9 +56,11 @@
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
+
import javax.swing.table.AbstractTableModel;
-import org.apache.log4j.Priority;
+
import org.apache.log4j.Category;
+import org.apache.log4j.Priority;
/**
* Represents a list of <code>EventDetails</code> objects that are sorted on
@@ -25,7 +69,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Oliver Burn</a>
*/
class MyTableModel
- extends AbstractTableModel
+ extends AbstractTableModel implements EventDetailSink
{
/** used to log messages **/
1.2 +5 -5
jakarta-log4j/src/java/org/apache/log4j/chainsaw/MyTableColumnModel.java
Index: MyTableColumnModel.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/MyTableColumnModel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MyTableColumnModel.java 25 Feb 2003 12:51:16 -0000 1.1
+++ MyTableColumnModel.java 10 Mar 2003 10:24:12 -0000 1.2
@@ -58,6 +58,7 @@
import javax.swing.table.TableColumn;
import org.apache.log4j.Logger;
+import javax.swing.table.TableModel;
/**
@@ -85,15 +86,14 @@
/** Map of TableColumns to PreferenceSets */
private final Map mColPrefMap = new HashMap();
- private final MyTableModel mTableModel;
+ private final TableModel mTableModel;
/**
* Construct a MyTableColumnModel.
- *
- * @param tableModel table model to work with
+ * @param aTableModel table model to work with
*/
- public MyTableColumnModel(MyTableModel tableModel) {
- mTableModel = tableModel;
+ public MyTableColumnModel(TableModel aTableModel) {
+ mTableModel = aTableModel;
}
/**
1.5 +113 -143 jakarta-log4j/src/java/org/apache/log4j/chainsaw/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/Main.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Main.java 25 Feb 2003 12:49:14 -0000 1.4
+++ Main.java 10 Mar 2003 10:24:12 -0000 1.5
@@ -50,12 +50,11 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
-import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import java.io.IOException;
-import java.util.Properties;
+
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JMenu;
@@ -67,8 +66,8 @@
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
-import org.apache.log4j.Category;
-import org.apache.log4j.PropertyConfigurator;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableModel;
/**
* The main application.
@@ -78,12 +77,6 @@
public class Main
extends JFrame
{
- /** the default port number to listen on **/
- private static final int DEFAULT_PORT = 4445;
-
- /** name of property for port name **/
- public static final String PORT_PROP_NAME = "chainsaw.port";
-
/** Window x-position property */
public static final String X_POSITION_PROPERTY =
Preferences.PROP_PREFIX + ".x";
@@ -100,95 +93,25 @@
public static final String DETAILS_SEPARATOR_PROPERTY =
Preferences.PROP_PREFIX + ".details.separator";
- /** use to log messages **/
- private static final Category LOG = Category.getInstance(Main.class);
-
private static final Preferences PREFS = Preferences.getInstance();
- private final JSplitPane aDetailsDivider;
+ private JSplitPane aDetailsDivider;
private final MyTableColumnModel mColumnModel;
/**
* Creates a new <code>Main</code> instance.
*/
- private Main() {
+ public Main() {
super("CHAINSAW - Log4J Log Viewer");
ExitAction.INSTANCE.addShutdownHook(new Thread(new Shutdown()));
- // create the all important model
- final MyTableModel model = new MyTableModel();
+ // create the all important models
+ final ChainsawAppender model = ChainsawAppender.getInstance();
mColumnModel = new MyTableColumnModel(model);
- //Create the menu bar.
- final JMenuBar menuBar = new JMenuBar();
- setJMenuBar(menuBar);
- final JMenu menu = new JMenu("File");
- menu.setMnemonic('F');
- menuBar.add(menu);
-
- try {
- final LoadXMLAction lxa = new LoadXMLAction(this, model);
- final JMenuItem loadMenuItem = new JMenuItem("Load file...");
- loadMenuItem.setMnemonic('L');
- menu.add(loadMenuItem);
- loadMenuItem.addActionListener(lxa);
- } catch (NoClassDefFoundError e) {
- LOG.info("Missing classes for XML parser", e);
- JOptionPane.showMessageDialog(
- this,
- "XML parser not in classpath - unable to load XML events.",
- "CHAINSAW",
- JOptionPane.ERROR_MESSAGE);
- } catch (Exception e) {
- LOG.info("Unable to create the action to load XML files", e);
- JOptionPane.showMessageDialog(
- this,
- "Unable to create a XML parser - unable to load XML events.",
- "CHAINSAW",
- JOptionPane.ERROR_MESSAGE);
- }
-
- final RecentFilesMenu recent = new RecentFilesMenu(model);
- recent.setMnemonic('R');
- menu.add(recent);
- PREFS.setRecentFilesMenu(recent);
- recent.rebuild();
-
- final JMenuItem prefsMenuItem = new JMenuItem("Preferences");
- prefsMenuItem.setMnemonic('P');
- menu.add(prefsMenuItem);
- prefsMenuItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- new PreferencesDialog(Main.this, mColumnModel).show();
- }
- });
-
- final JMenuItem exitMenuItem = new JMenuItem("Exit");
- exitMenuItem.setMnemonic('x');
- menu.add(exitMenuItem);
- exitMenuItem.addActionListener(ExitAction.INSTANCE);
-
- // Add control panel
- final ControlPanel cp = new ControlPanel(model);
- getContentPane().add(cp, BorderLayout.NORTH);
-
- // Create the table
- final JTable table = new JTable(model, mColumnModel);
- table.setAutoCreateColumnsFromModel(true);
- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- final JScrollPane scrollPane = new JScrollPane(table);
- scrollPane.setBorder(BorderFactory.createTitledBorder("Events: "));
- scrollPane.setPreferredSize(new Dimension(900, 300));
-
- // Create the details
- final JPanel details = new DetailPanel(table, model);
- details.setPreferredSize(new Dimension(900, 100));
-
- // Add the table and stack trace into a splitter
- aDetailsDivider = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
- scrollPane, details);
- getContentPane().add(aDetailsDivider, BorderLayout.CENTER);
+ buildMenus(model);
+ buildComponents(model);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent aEvent) {
@@ -199,45 +122,106 @@
loadGuiPrefs();
setVisible(true);
- setupReceiver(model);
}
/**
- * Setup recieving messages.
- *
- * @param aModel a <code>MyTableModel</code> value
+ * Constructs the JTable used for displaying the Events logs
+ * @param tableModel
+ * @param tableColumnModel
+ * @return
*/
- private void setupReceiver(MyTableModel aModel) {
- int port = DEFAULT_PORT;
- final String strRep = System.getProperty(PORT_PROP_NAME);
- if (strRep != null) {
- try {
- port = Integer.parseInt(strRep);
- } catch (NumberFormatException nfe) {
- LOG.fatal("Unable to parse " + PORT_PROP_NAME +
- " property with value " + strRep + ".");
- JOptionPane.showMessageDialog(
- this,
- "Unable to parse port number from '" + strRep +
- "', quitting.",
- "CHAINSAW",
- JOptionPane.ERROR_MESSAGE);
- System.exit(1);
- }
- }
+ private JTable buildTable(TableModel tableModel, TableColumnModel
tableColumnModel)
+ {
+ final JTable table = new JTable(tableModel, mColumnModel);
+ table.setAutoCreateColumnsFromModel(true);
+ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ return table;
+ }
+
+ /**
+ * Constructs all the components required for this frame
+ * and attaches the ChainsawAppender to components that require it
+ * @param model
+ */
+ private void buildComponents(ChainsawAppender model)
+ {
+ // Add control panel
+ final ControlPanel cp = new ControlPanel(model.getWrappedModel());
+ getContentPane().add(cp, BorderLayout.NORTH);
+
+ // Create the table
+ final JTable table = buildTable(model, mColumnModel);
+ final JScrollPane scrollPane = new JScrollPane(table);
+ scrollPane.setBorder(BorderFactory.createTitledBorder("Events: "));
+ scrollPane.setPreferredSize(new Dimension(900, 300));
+
+ // Create the details
+ final JPanel details = new DetailPanel(table, model.getWrappedModel());
+ details.setPreferredSize(new Dimension(900, 100));
+
+ // Add the table and stack trace into a splitter
+ aDetailsDivider = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
+ scrollPane, details);
+ getContentPane().add(aDetailsDivider, BorderLayout.CENTER);
+
+ }
+
+ /**
+ * Initialises the Menu bar for this frame, and bind
+ * actions
+ * @param eventSink
+ */
+ private void buildMenus(EventDetailSink eventSink)
+ {
+ //Create the menu bar.
+ final JMenuBar menuBar = new JMenuBar();
+ setJMenuBar(menuBar);
+ final JMenu menu = new JMenu("File");
+ menu.setMnemonic('F');
+ menuBar.add(menu);
+
+ try {
+ final LoadXMLAction lxa = new LoadXMLAction(this, eventSink);
+ final JMenuItem loadMenuItem = new JMenuItem("Load file...");
+ loadMenuItem.setMnemonic('L');
+ menu.add(loadMenuItem);
+ loadMenuItem.addActionListener(lxa);
+ } catch (NoClassDefFoundError e) {
+ System.err.println("Missing classes for XML parser :" +e );
+ JOptionPane.showMessageDialog(
+ this,
+ "XML parser not in classpath - unable to load XML events.",
+ "CHAINSAW",
+ JOptionPane.ERROR_MESSAGE);
+ } catch (Exception e) {
+ System.err.println("Unable to create the action to load XML files:" +
e.getMessage());
+ JOptionPane.showMessageDialog(
+ this,
+ "Unable to create a XML parser - unable to load XML events.",
+ "CHAINSAW",
+ JOptionPane.ERROR_MESSAGE);
+ }
+
+ final RecentFilesMenu recent = new RecentFilesMenu(eventSink);
+ recent.setMnemonic('R');
+ menu.add(recent);
+ PREFS.setRecentFilesMenu(recent);
+ recent.rebuild();
+
+ final JMenuItem prefsMenuItem = new JMenuItem("Preferences");
+ prefsMenuItem.setMnemonic('P');
+ menu.add(prefsMenuItem);
+ prefsMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ new PreferencesDialog(Main.this, mColumnModel).show();
+ }
+ });
+
+ final JMenuItem exitMenuItem = new JMenuItem("Exit");
+ exitMenuItem.setMnemonic('x');
+ menu.add(exitMenuItem);
+ exitMenuItem.addActionListener(ExitAction.INSTANCE);
- try {
- final LoggingReceiver lr = new LoggingReceiver(aModel, port);
- lr.start();
- } catch (IOException e) {
- LOG.fatal("Unable to connect to socket server, quiting", e);
- JOptionPane.showMessageDialog(
- this,
- "Unable to create socket on port " + port + ", quitting.",
- "CHAINSAW",
- JOptionPane.ERROR_MESSAGE);
- System.exit(1);
- }
}
private void loadGuiPrefs() {
@@ -278,31 +262,17 @@
// static methods
////////////////////////////////////////////////////////////////////////////
-
- /** initialise log4j **/
- private static void initLog4J() {
- final Properties props = new Properties();
- props.setProperty("log4j.rootCategory", "DEBUG, A1");
- props.setProperty("log4j.appender.A1",
- "org.apache.log4j.ConsoleAppender");
- props.setProperty("log4j.appender.A1.layout",
- "org.apache.log4j.TTCCLayout");
- PropertyConfigurator.configure(props);
- }
-
- /**
- * The main method.
- *
- * @param aArgs ignored
- */
- public static void main(String[] aArgs) {
- initLog4J();
- new Main();
- }
-
private class Shutdown implements Runnable {
public void run() {
saveGuiPrefs();
}
+ }
+
+ /**
+ * @deprecated, should be started from the Start class
+ * @param args
+ */
+ public static void main(String[] args) {
+ Start.main(args);
}
}
1.4 +5 -5
jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingReceiver.java
Index: LoggingReceiver.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingReceiver.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LoggingReceiver.java 25 May 2002 12:38:02 -0000 1.3
+++ LoggingReceiver.java 10 Mar 2003 10:24:12 -0000 1.4
@@ -52,7 +52,7 @@
new ObjectInputStream(mClient.getInputStream());
while (true) {
final LoggingEvent event = (LoggingEvent) ois.readObject();
- mModel.addEvent(new EventDetails(event));
+ mEventSink.addEvent(new EventDetails(event));
}
} catch (EOFException e) {
LOG.info("Reached EOF, closing connection");
@@ -73,7 +73,7 @@
}
/** where to put the events **/
- private final MyTableModel mModel;
+ private final EventDetailSink mEventSink;
/** server for listening for connections **/
private final ServerSocket mSvrSock;
@@ -81,13 +81,13 @@
/**
* Creates a new <code>LoggingReceiver</code> instance.
*
- * @param aModel model to place put received into
+ * @param aEventSink eventSink to place put received into
* @param aPort port to listen on
* @throws IOException if an error occurs
*/
- LoggingReceiver(MyTableModel aModel, int aPort) throws IOException {
+ LoggingReceiver(EventDetailSink aEventSink, int aPort) throws IOException {
setDaemon(true);
- mModel = aModel;
+ this.mEventSink = aEventSink;
mSvrSock = new ServerSocket(aPort);
}
1.3 +6 -7
jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoadXMLAction.java
Index: LoadXMLAction.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoadXMLAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LoadXMLAction.java 25 Feb 2003 12:49:14 -0000 1.2
+++ LoadXMLAction.java 10 Mar 2003 10:24:12 -0000 1.3
@@ -56,7 +56,7 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
/**
* Encapsulates the action to load an XML file.
@@ -68,8 +68,8 @@
extends AbstractAction
{
/** use to log messages **/
- private static final Category LOG =
- Category.getInstance(LoadXMLAction.class);
+ private static final Logger LOG =
+ Logger.getLogger(LoadXMLAction.class);
/** the parent frame **/
private final JFrame mParent;
@@ -92,12 +92,12 @@
* Creates a new <code>LoadXMLAction</code> instance.
*
* @param aParent the parent frame
- * @param aModel the model to add events to
+ * @param eventSink the eventSink to add events to
*/
- LoadXMLAction(JFrame aParent, MyTableModel aModel)
+ LoadXMLAction(JFrame aParent, EventDetailSink eventSink)
{
mParent = aParent;
- mHandler = new XMLFileHandler(aModel);
+ mHandler = new XMLFileHandler(eventSink);
}
/**
@@ -126,5 +126,4 @@
}
}
}
-
}
1.2 +47 -4
jakarta-log4j/src/java/org/apache/log4j/chainsaw/DetailPanel.java
Index: DetailPanel.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/DetailPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DetailPanel.java 23 Mar 2002 07:51:26 -0000 1.1
+++ DetailPanel.java 10 Mar 2003 10:24:12 -0000 1.2
@@ -1,9 +1,52 @@
/*
- * Copyright (C) The Apache Software Foundation. All rights reserved.
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
*
- * This software is published under the terms of the Apache Software
- * License version 1.1, a copy of which has been included with this
- * distribution in the LICENSE.txt file. */
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
package org.apache.log4j.chainsaw;
import java.awt.BorderLayout;
1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/log4j.xml
Index: log4j.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="Chainsaw" class="org.apache.log4j.chainsaw.ChainsawAppender" />
<appender name="A2" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.SimpleLayout" />
</appender>
<plugin name="SocketReceiver" class="org.apache.log4j.net.SocketReceiver">
<param name="Port" value="4445" />
</plugin>
<logger name="org.apache.log4j.chainsaw" additivity="false">
<level value="info" />
<!--<appender-ref ref="A2" />-->
</logger>
<root>
<level value="debug" />
<appender-ref ref="Chainsaw" />
</root>
</log4j:configuration>
1.1 jakarta-log4j/src/java/org/apache/log4j/chainsaw/Start.java
Index: Start.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package org.apache.log4j.chainsaw;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import org.apache.log4j.xml.DOMConfigurator;
/**
* Main initialization point of Chainsaw
* @author Paul Smith
* @version 1.0
*/
public class Start {
public static void main(String[] args) {
initLog4J();
new Main();
}
private static void initLog4J()
{
/** initialise log4j **/
final FinderStrategies strategies = new FinderStrategies();
final URL url = strategies.findConfiguration();
DOMConfigurator.configure( url );
}
private static class FinderStrategies implements Log4JConfigurationFinder
{
public FinderStrategies()
{
mStrategies.add(new ResourceLoaderFinder());
mStrategies.add(new FileOpenFinder());
// TODO: add any more stategies
}
public URL findConfiguration()
{
for (Iterator i = mStrategies.iterator(); i.hasNext(); ) {
final Log4JConfigurationFinder finder =
(Log4JConfigurationFinder) i.next();
final URL resource = finder.findConfiguration();
if (resource != null) {
return resource;
}
}
throw new RuntimeException("Failed to locate a Log4J configuration"
+ " via any means");
}
private final Collection mStrategies = new ArrayList();
}
/**
* Finds the config file by looking for it using a Classloader.getResource()
* @author Paul Smith
* @version 1.0
*/
private static class ResourceLoaderFinder implements Log4JConfigurationFinder
{
public URL findConfiguration()
{
return this.getClass().getClassLoader().getResource(LOG4J_CONFIG_FILE);
}
}
private static final String LOG4J_CONFIG_FILE = "log4j.xml";
/**
* Allows the user to locate the Log4J initialization file
* by showing a JFileChooser
* @author Paul Smith
* @version 1.0
*/
private static class FileOpenFinder implements Log4JConfigurationFinder
{
public URL findConfiguration()
{
final JFileChooser chooser = new JFileChooser();
chooser.setFileFilter( LOG4J_FILE_FILTER );
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
final File f = chooser.getSelectedFile();
try {
return f.toURL();
}
catch (MalformedURLException ex) {
ex.printStackTrace();
}
}
return null;
}
private static FileFilter LOG4J_FILE_FILTER = new FileFilter(){
public boolean accept(File f)
{
return f.isDirectory() || f.getName().equals(LOG4J_CONFIG_FILE);
}
/**
* The description of this filter. For example: "JPG and GIF Images"
* @see FileView#getName
*/
public String getDescription()
{
return "Log4J Configuration File";
}
};
}
}
1.1
jakarta-log4j/src/java/org/apache/log4j/chainsaw/Log4JConfigurationFinder.java
Index: Log4JConfigurationFinder.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package org.apache.log4j.chainsaw;
import java.net.URL;
public interface Log4JConfigurationFinder {
public URL findConfiguration();
}
1.1
jakarta-log4j/src/java/org/apache/log4j/chainsaw/EventDetailSink.java
Index: EventDetailSink.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package org.apache.log4j.chainsaw;
/**
* Simple interface for objects that can receive/work with EventDetails
* instances
* @author Paul Smith
* @version 1.0
*/
public interface EventDetailSink {
public void addEvent(EventDetails aDetail);
}
1.1
jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawAppender.java
Index: ChainsawAppender.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package org.apache.log4j.chainsaw;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
/**
* ChainsawAppender receives LoggingEvents from the local
* Log4J environment, and appends them into a model that
* can be used inside a Swing GUI
* @author Paul Smith
* @version 1.0
*/
public class ChainsawAppender
extends AppenderSkeleton
implements EventDetailSink, TableModel {
private static MyTableModel sSharedModel;
private final MyTableModel wrappedTableModel = getDefaultModel();
private static ChainsawAppender sSharedAppender = null;
public ChainsawAppender() {
synchronized (ChainsawAppender.class) {
if (sSharedAppender == null) {
sSharedAppender = this;
}
}
}
/**
* Returns the singleton MyTableModel instance that has been configured.
*
* This will be eventually replaced to allow each ChainsawAppender
* to have it's own model, but for now it's important that all log events
* received inside Chainsaw go to a single model.
* @return MyTableModel
*/
private static synchronized MyTableModel getDefaultModel()
{
if (sSharedModel == null) {
sSharedModel = new MyTableModel();
}
return sSharedModel;
}
/**
* Return the singleton instance of the ChainsawAppender, it should only
* be initialised once.
* @return
*/
static ChainsawAppender getInstance()
{
return sSharedAppender;
}
/**
* Returns the internally wrapped Model
*
* NOTE: it is strongly recommended at this time not to rely on this method
* until further refactoring is completed.
* @return MyTableModel
*/
MyTableModel getWrappedModel()
{
return wrappedTableModel;
}
public boolean requiresLayout() {
return false;
}
/**
* Implements the EventDetailSink interface by forwarding the EventDetails
* object onto an internal Model
*/
public void addEvent(EventDetails aDetails)
{
synchronized (wrappedTableModel) {
wrappedTableModel.addEvent(aDetails);
}
}
/**
* Appends the event into the internal wrapped TableModel
* @param aEvent the LoggingEvent to append
*/
protected void append(LoggingEvent aEvent) {
synchronized (wrappedTableModel) {
wrappedTableModel.addEvent(new EventDetails(aEvent));
}
}
/**
* Close does nothing
*/
public void close() {
// TODO: perhaps it should clear the internal TableModel
}
// ==========================================================================
// All methods here are from TableModel, and simply forward on to the
// internal wrappedTableModel instance
// ==========================================================================
public int getRowCount() {
return wrappedTableModel.getRowCount();
}
public int getColumnCount() {
return wrappedTableModel.getColumnCount();
}
public String getColumnName(int aColumnIndex) {
return wrappedTableModel.getColumnName(aColumnIndex);
}
public Class getColumnClass(int columnIndex) {
return wrappedTableModel.getColumnClass(columnIndex);
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return wrappedTableModel.isCellEditable(rowIndex, columnIndex);
}
public Object getValueAt(int rowIndex, int columnIndex) {
return wrappedTableModel.getValueAt(rowIndex, columnIndex);
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
wrappedTableModel.setValueAt(aValue, rowIndex, columnIndex);
}
public void addTableModelListener(TableModelListener l) {
wrappedTableModel.addTableModelListener(l);
}
public void removeTableModelListener(TableModelListener l) {
wrappedTableModel.removeTableModelListener(l);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]