You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by sd...@apache.org on 2003/04/29 18:21:31 UTC
cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/examples log4jsink.xml log4jsource.xml
sdeboy 2003/04/29 09:21:30
Modified: src/java/org/apache/log4j/chainsaw ChainsawAppender.java
ChainsawAppenderHandler.java DisplayFilter.java
ExpressionEvaluatorFactory.java JSortTable.java
LogUI.java
src/java/org/apache/log4j/net SocketReceiver.java
UDPAppender.java UDPReceiver.java
src/java/org/apache/log4j/servlet ConfigurationServlet.java
src/java/org/apache/log4j/xml XMLLayout.java
Added: src/config log4j-appender-sample.xml
log4j-receiver-sample.xml
src/java/org/apache/log4j/net MulticastAppender.java
MulticastReceiver.java
Removed: src/java/org/apache/log4j/xml/examples log4jsink.xml
log4jsource.xml
Log:
Renamed previous multicast-based appenders/receiver pair (UDPAppender/UDPReceiver) to MulticastAppender/MulticastReceiver.
Created new UDP-based (non-multicast) appenders as UDPAppender/UDPReceiver.
Removed xml examples directory - added more complete appender/receiver xml examples to config directory
Removed unneeded imports.
Revision Changes Path
1.1 jakarta-log4j-sandbox/src/config/log4j-appender-sample.xml
Index: log4j-appender-sample.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<appender name="LOGUI" class="org.apache.log4j.chainsaw.ChainsawAppender">
<param name="viewerClass" value="org.apache.log4j.chainsaw.LogUI"/>
</appender>
<appender name="UDPCHAINSAW" class="org.apache.log4j.net.UDPAppender">
<param name="remoteHost" value="localhost"/>
<param name="port" value="4446"/>
<param name="log4JApp" value="udp-generator"/>
<layout class="org.apache.log4j.xml.XMLLayout">
<param name="LocationInfo" value="true"/>
</layout>
</appender>
<appender name="TCPCHAINSAW" class="org.apache.log4j.net.SocketAppender">
<param name="remoteHost" value="localhost"/>
<param name="port" value="4448"/>
<param name="log4JApp" value="tcp-generator"/>
<param name="LocationInfo" value="true"/>
</appender>
<appender name="MULTICASTCHAINSAW" class="org.apache.log4j.net.MulticastAppender">
<param name="remoteHost" value="224.1.1.1"/>
<param name="port" value="4449"/>
<param name="timeToLive" value="1"/>
<param name="log4JApp" value="multicast-generator"/>
<layout class="org.apache.log4j.xml.XMLLayout">
<param name="LocationInfo" value="true"/>
</layout>
</appender>
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.SimpleLayout"/>
</appender>
<root>
<level value="debug"/>
<appender-ref ref="UDPCHAINSAW"/>
<appender-ref ref="MULTICASTCHAINSAW"/>
<appender-ref ref="TCPCHAINSAW"/>
<appender-ref ref="STDOUT"/>
</root>
</log4j:configuration>
1.1 jakarta-log4j-sandbox/src/config/log4j-receiver-sample.xml
Index: log4j-receiver-sample.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<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="4448"/>
</plugin>
<plugin name="UDPReceiver" class="org.apache.log4j.net.UDPReceiver">
<param name="Port" value="4446"/>
</plugin>
<plugin name="MulticastReceiver" class="org.apache.log4j.net.MulticastReceiver">
<param name="Port" value="4449"/>
<param name="Address" value="224.1.1.1"/>
</plugin>
<root>
<level value="debug"/>
</root>
</log4j:configuration>
1.2 +0 -2 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawAppender.java
Index: ChainsawAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawAppender.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ChainsawAppender.java 28 Apr 2003 06:58:31 -0000 1.1
+++ ChainsawAppender.java 29 Apr 2003 16:21:29 -0000 1.2
@@ -49,8 +49,6 @@
package org.apache.log4j.chainsaw;
import java.util.ArrayList;
-import java.util.Iterator;
-
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
1.2 +0 -4 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java
Index: ChainsawAppenderHandler.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawAppenderHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ChainsawAppenderHandler.java 28 Apr 2003 05:44:31 -0000 1.1
+++ ChainsawAppenderHandler.java 29 Apr 2003 16:21:29 -0000 1.2
@@ -55,14 +55,10 @@
import org.apache.log4j.spi.LoggingEvent;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import java.util.Vector;
-
-import javax.swing.SwingUtilities;
/**
1.2 +0 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DisplayFilter.java
Index: DisplayFilter.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/DisplayFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DisplayFilter.java 28 Apr 2003 05:44:32 -0000 1.1
+++ DisplayFilter.java 29 Apr 2003 16:21:29 -0000 1.2
@@ -58,7 +58,6 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import java.util.Vector;
1.2 +0 -1 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ExpressionEvaluatorFactory.java
Index: ExpressionEvaluatorFactory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ExpressionEvaluatorFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExpressionEvaluatorFactory.java 28 Apr 2003 05:44:31 -0000 1.1
+++ ExpressionEvaluatorFactory.java 29 Apr 2003 16:21:29 -0000 1.2
@@ -51,7 +51,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
/**
1.2 +8 -7 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/JSortTable.java
Index: JSortTable.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/JSortTable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JSortTable.java 28 Apr 2003 05:44:31 -0000 1.1
+++ JSortTable.java 29 Apr 2003 16:21:29 -0000 1.2
@@ -49,14 +49,15 @@
package org.apache.log4j.chainsaw;
-import java.awt.*;
-import java.awt.event.*;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.Vector;
-import java.util.*;
-
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.table.*;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableColumnModel;
/**
1.2 +4 -14 jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java
Index: LogUI.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/LogUI.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LogUI.java 28 Apr 2003 05:44:31 -0000 1.1
+++ LogUI.java 29 Apr 2003 16:21:29 -0000 1.2
@@ -184,15 +184,9 @@
JMenuBar menuBar = new JMenuBar();
JMenu activeTabMenu = new JMenu("Current tab");
- JMenuItem menuItemDisplayFilter =
- new JMenuItem("Define display and color filters...");
- JCheckBoxMenuItem menuItemToggleDetails =
- new JCheckBoxMenuItem("Show Detail Pane");
- JMenuItem menuItemClear =
- new JMenuItem("Clear all entries for this panel");
- JMenuItem menuItemRecoverPanes = new JMenuItem("Recover closed panes");
- JCheckBoxMenuItem menuItemPause = new JCheckBoxMenuItem("Pause");
- JMenuItem menuItemClose = new JMenuItem("Close tab");
+ JMenuItem menuItemClose = new JMenuItem("Close Welcome tab");
+ JMenuItem menuItemUseRightMouse=new JMenuItem("Other options available via panel's right mouse button popup menu");
+ menuItemUseRightMouse.setEnabled(false);
menuItemClose.addActionListener(
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
@@ -205,11 +199,7 @@
});
activeTabMenu.add(menuItemClose);
- activeTabMenu.add(menuItemDisplayFilter);
- activeTabMenu.add(menuItemToggleDetails);
- activeTabMenu.add(menuItemClear);
- activeTabMenu.add(menuItemRecoverPanes);
- activeTabMenu.add(menuItemPause);
+ activeTabMenu.add(menuItemUseRightMouse);
menuBar.add(activeTabMenu);
setJMenuBar(menuBar);
}
1.2 +0 -2 jakarta-log4j-sandbox/src/java/org/apache/log4j/net/SocketReceiver.java
Index: SocketReceiver.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/net/SocketReceiver.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SocketReceiver.java 28 Apr 2003 05:44:33 -0000 1.1
+++ SocketReceiver.java 29 Apr 2003 16:21:30 -0000 1.2
@@ -49,11 +49,9 @@
package org.apache.log4j.net;
-import org.apache.log4j.Logger;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.spi.LoggerRepository;
-import org.apache.log4j.spi.LoggingEvent;
import java.net.ServerSocket;
import java.net.Socket;
1.2 +7 -25 jakarta-log4j-sandbox/src/java/org/apache/log4j/net/UDPAppender.java
Index: UDPAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/net/UDPAppender.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UDPAppender.java 28 Apr 2003 05:44:33 -0000 1.1
+++ UDPAppender.java 29 Apr 2003 16:21:30 -0000 1.2
@@ -50,15 +50,14 @@
package org.apache.log4j.net;
import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.Layout;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.spi.LoggingEvent;
import java.io.IOException;
import java.net.DatagramPacket;
+import java.net.DatagramSocket;
import java.net.InetAddress;
-import java.net.MulticastSocket;
import java.net.UnknownHostException;
@@ -102,10 +101,9 @@
String remoteHost;
String log4japp;
String overrideProperties = "true";
- int timeToLive;
InetAddress address;
int port = DEFAULT_PORT;
- MulticastSocket outSocket;
+ DatagramSocket outSocket;
int reconnectionDelay = DEFAULT_RECONNECTION_DELAY;
boolean locationInfo = false;
int count = 0;
@@ -205,8 +203,8 @@
try {
// First, close the previous connection if any.
cleanUp();
- outSocket = new MulticastSocket();
- outSocket.setTimeToLive(timeToLive);
+ outSocket = new DatagramSocket();
+ outSocket.connect(address, port);
} catch (IOException e) {
LogLog.error(
"Could not open UDP Socket for sending. We will try again later.", e);
@@ -328,22 +326,7 @@
return overrideProperties;
}
- /**
- The <b>Time to live</b> option takes a positive integer representing
- the time to live value.
- */
- public void setTimeToLive(int timeToLive) {
- this.timeToLive = timeToLive;
- }
-
- /**
- Returns value of the <b>Time to Live</b> option.
- */
- public int getTimeToLive() {
- return timeToLive;
- }
-
- /**
+ /**
The <b>Port</b> option takes a positive integer representing
the port where UDP packets will be sent.
*/
@@ -394,17 +377,16 @@
boolean interrupted = false;
public void run() {
- MulticastSocket socket;
+ DatagramSocket socket;
while (!interrupted) {
try {
sleep(reconnectionDelay);
LogLog.debug("Attempting to establish UDP Datagram Socket");
- socket = new MulticastSocket();
+ socket = new DatagramSocket();
synchronized (this) {
outSocket = socket;
- outSocket.setTimeToLive(timeToLive);
connector = null;
break;
1.2 +3 -24 jakarta-log4j-sandbox/src/java/org/apache/log4j/net/UDPReceiver.java
Index: UDPReceiver.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/net/UDPReceiver.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UDPReceiver.java 28 Apr 2003 05:44:33 -0000 1.1
+++ UDPReceiver.java 29 Apr 2003 16:21:30 -0000 1.2
@@ -56,10 +56,8 @@
import java.io.IOException;
import java.net.DatagramPacket;
-import java.net.InetAddress;
-import java.net.MulticastSocket;
+import java.net.DatagramSocket;
import java.net.SocketException;
-import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Iterator;
@@ -76,8 +74,7 @@
private static final int PACKET_LENGTH = 8192;
private boolean isActive = false;
private int port;
- private String address;
- private MulticastSocket socket = null;
+ private DatagramSocket socket = null;
private final XMLDecoder decoder = new XMLDecoder();
private final UDPThread receiverThread = new UDPThread();
private final HandlerThread handlerThread = new HandlerThread();
@@ -90,18 +87,10 @@
this.port = port;
}
- public String getAddress() {
- return address;
- }
-
public synchronized void shutdown() {
isActive = false;
}
- public void setAddress(String address) {
- this.address = address;
- }
-
/**
Returns true if this receiver is active. */
public synchronized boolean isActive() {
@@ -115,18 +104,8 @@
}
public void activateOptions() {
- InetAddress addr = null;
-
- try {
- addr = InetAddress.getByName(address);
- } catch (UnknownHostException uhe) {
- uhe.printStackTrace();
- System.exit(1);
- }
-
try {
- socket = new MulticastSocket(port);
- socket.joinGroup(addr);
+ socket = new DatagramSocket(port);
receiverThread.start();
handlerThread.start();
} catch (IOException ioe) {
1.1 jakarta-log4j-sandbox/src/java/org/apache/log4j/net/MulticastAppender.java
Index: MulticastAppender.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
* apache@apache.org.
*
* 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.net;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.spi.LoggingEvent;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
/**
* Multicast-based Appender. Works in conjunction with the MulticastReceiver, which expects
* a LoggingEvent encoded using XMLLayout.
*
* Sends log information as a multicast datagrams.
*
* <p>Messages are not sent as LoggingEvent objects but as text after
* applying XMLLayout.
*
* <p>The port and remoteHost properties can be set in configuration properties.
* By setting the remoteHost to a broadcast address any number of clients can
* listen for log messages.
*
* <p>This was inspired and really extended/copied from {@link SocketAppender}. Please
* see the docs for the proper credit to the authors of that class.
*
* @author <a href="mailto:kbrown@versatilesolutions.com">Kevin Brown</a>
*
*/
public class MulticastAppender extends AppenderSkeleton {
/**
The default port number for the multicast packets. (9991).
*/
static final int DEFAULT_PORT = 9991;
/**
The default reconnection delay (30000 milliseconds or 30 seconds).
*/
static final int DEFAULT_RECONNECTION_DELAY = 30000;
/**
We remember host name as String in addition to the resolved
InetAddress so that it can be returned via getOption().
*/
String localMachine;
String remoteHost;
String log4japp;
String overrideProperties = "true";
int timeToLive;
InetAddress address;
int port = DEFAULT_PORT;
MulticastSocket outSocket;
int reconnectionDelay = DEFAULT_RECONNECTION_DELAY;
boolean locationInfo = false;
int count = 0;
public MulticastAppender() {
}
/**
Sends multicast packets to the <code>address</code> and <code>port</code>.
*/
public MulticastAppender(InetAddress address, int port) {
this.address = address;
this.remoteHost = address.getHostName();
this.port = port;
connect(address, port);
}
/**
Sends multicast packets to the <code>address</code> and <code>port</code>.
*/
public MulticastAppender(String host, int port) {
this.port = port;
this.address = getAddressByName(host);
this.remoteHost = host;
connect(address, port);
}
/**
Open the multicast sender for the <b>RemoteHost</b> and <b>Port</b>.
*/
public void activateOptions() {
try {
localMachine = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException uhe) {
try {
localMachine = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException uhe2) {
localMachine = "unknown";
}
}
//allow system property of log4japp to be primary
if (log4japp == null) {
log4japp = System.getProperty("log4japp");
} else {
if (System.getProperty("log4japp") != null) {
log4japp = log4japp + "-" + System.getProperty("log4japp");
}
}
connect(address, port);
}
/**
Close this appender.
<p>This will mark the appender as closed and
call then {@link #cleanUp} method.
*/
public synchronized void close() {
if (closed) {
return;
}
this.closed = true;
cleanUp();
}
/**
Close the Socket and release the underlying
connector thread if it has been created
*/
public void cleanUp() {
if (outSocket != null) {
try {
outSocket.close();
} catch (Exception e) {
LogLog.error("Could not close outSocket.", e);
}
outSocket = null;
}
}
void connect(InetAddress address, int port) {
if (this.address == null) {
return;
}
try {
// First, close the previous connection if any.
cleanUp();
outSocket = new MulticastSocket();
outSocket.setTimeToLive(timeToLive);
} catch (IOException e) {e.printStackTrace();
}
}
public void append(LoggingEvent event) {
if (event == null) {
return;
}
if (address == null) {
errorHandler.error(
"No remote host is set for MulticastAppender named \"" + this.name + "\".");
return;
}
if (outSocket != null) {
//if the values already exist, don't set (useful when forwarding from a simplesocketserver
if (
(overrideProperties != null)
&& overrideProperties.equalsIgnoreCase("true")) {
event.setProperty("log4jmachinename", localMachine);
if (log4japp != null) {
event.setProperty("log4japp", log4japp);
}
}
try {
byte[] logData = this.layout.format(event).trim().getBytes("ASCII");
DatagramPacket dp =
new DatagramPacket(logData, logData.length, address, port);
outSocket.send(dp);
} catch (IOException e) {
outSocket = null;
LogLog.warn("Detected problem with Multicast connection: " + e);
}
}
}
static InetAddress getAddressByName(String host) {
try {
return InetAddress.getByName(host);
} catch (Exception e) {
LogLog.error("Could not find address of [" + host + "].", e);
return null;
}
}
/**
The MulticastAppender uses layouts (should be configured with XMLLayout to use MulticastReceiver.
Hence, this method returns
<code>true</code>.
*/
public boolean requiresLayout() {
return true;
}
/**
The <b>RemoteHost</b> option takes a string value which should be
the host name or ipaddress to send the multicast packets.
*/
public void setRemoteHost(String host) {
address = getAddressByName(host);
remoteHost = host;
}
/**
Returns value of the <b>RemoteHost</b> option.
*/
public String getRemoteHost() {
return remoteHost;
}
/**
The <b>App</b> option takes a string value which should be the name of the application getting logged.
If property was already set (via system property), don't set here.
*/
public void setLog4JApp(String log4japp) {
this.log4japp = log4japp;
}
/**
Returns value of the <b>App</b> option.
*/
public String getLog4JApp() {
return log4japp;
}
/**
The <b>OverrideProperties</b> option allows configurations where the appender does not apply
the machinename/appname properties - the properties will be used as provided.
*/
public void setOverrideProperties(String overrideProperties) {
this.overrideProperties = overrideProperties;
}
/**
Returns value of the <b>OverrideProperties</b> option.
*/
public String getOverrideProperties() {
return overrideProperties;
}
/**
The <b>Time to live</b> option takes a positive integer representing
the time to live value.
*/
public void setTimeToLive(int timeToLive) {
this.timeToLive = timeToLive;
}
/**
Returns value of the <b>Time to Live</b> option.
*/
public int getTimeToLive() {
return timeToLive;
}
/**
The <b>Port</b> option takes a positive integer representing
the port where multicast packets will be sent.
*/
public void setPort(int port) {
this.port = port;
}
/**
Returns value of the <b>Port</b> option.
*/
public int getPort() {
return port;
}
/**
The <b>ReconnectionDelay</b> option takes a positive integer
representing the number of milliseconds to wait between each
failed attempt to establish an outgoing socket. The default value of
this option is 30000 which corresponds to 30 seconds.
<p>Setting this option to zero turns off reconnection
capability.
*/
public void setReconnectionDelay(int delay) {
this.reconnectionDelay = delay;
}
/**
Returns value of the <b>ReconnectionDelay</b> option.
*/
public int getReconnectionDelay() {
return reconnectionDelay;
}
}
1.1 jakarta-log4j-sandbox/src/java/org/apache/log4j/net/MulticastReceiver.java
Index: MulticastReceiver.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
* apache@apache.org.
*
* 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.net;
import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.xml.XMLDecoder;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Multicast-based receiver. Accepts LoggingEvents encoded using
* MulticastAppender and XMLLayout. The the XML data is converted
* back to a LoggingEvent and is posted.
*
* @author Scott Deboy <sd...@apache.org>
*
*/
public class MulticastReceiver extends Receiver {
private static final int PACKET_LENGTH = 8192;
private boolean isActive = false;
private int port;
private String address;
private MulticastSocket socket = null;
private final XMLDecoder decoder = new XMLDecoder();
private final UDPThread receiverThread = new UDPThread();
private final HandlerThread handlerThread = new HandlerThread();
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getAddress() {
return address;
}
public synchronized void shutdown() {
isActive = false;
}
public void setAddress(String address) {
this.address = address;
}
/**
Returns true if this receiver is active. */
public synchronized boolean isActive() {
return isActive;
}
/**
Sets the flag to indicate if receiver is active or not. */
protected synchronized void setActive(boolean isActive) {
this.isActive = isActive;
}
public void activateOptions() {
InetAddress addr = null;
try {
addr = InetAddress.getByName(address);
} catch (UnknownHostException uhe) {
uhe.printStackTrace();
}
try {
socket = new MulticastSocket(port);
socket.joinGroup(addr);
receiverThread.start();
handlerThread.start();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
class HandlerThread extends Thread {
private ArrayList list = new ArrayList();
public HandlerThread() {
setDaemon(true);
}
public void append(String data) {
synchronized (list) {
list.add(data);
}
}
public synchronized void run() {
ArrayList list2 = new ArrayList();
while (isAlive()) {
synchronized (list) {
if (list.size() > 0) {
list2.addAll(list);
list.clear();
}
}
if (list2.size() > 0) {
Iterator iter = list2.iterator();
while (iter.hasNext()) {
String data = (String) iter.next();
LoggingEvent e = decoder.decode(data);
doPost(e);
}
list2.clear();
} else {
try {
wait(1000);
} catch (InterruptedException ie) {
}
}
}
}
}
class UDPThread extends Thread {
public UDPThread() {
setDaemon(true);
}
public void run() {
setActive(true);
byte[] b = new byte[PACKET_LENGTH];
DatagramPacket p = new DatagramPacket(b, b.length);
while (isActive) {
try {
socket.receive(p);
String data = new String(p.getData(), 0, p.getLength()).trim();
handlerThread.append(data);
} catch (SocketException se) {
se.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
}
1.5 +2 -2 jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/ConfigurationServlet.java
Index: ConfigurationServlet.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/ConfigurationServlet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigurationServlet.java 20 Mar 2003 07:19:24 -0000 1.4
+++ ConfigurationServlet.java 29 Apr 2003 16:21:30 -0000 1.5
@@ -266,8 +266,8 @@
try {
logger =
- (className.equals(ROOT)) ? logger.getRootLogger()
- : logger.getLogger(className);
+ (className.equals(ROOT)) ? Logger.getRootLogger()
+ : Logger.getLogger(className);
logger.setLevel(Level.toLevel(level));
} catch (Exception e) {
1.2 +3 -6 jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java
Index: XMLLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLLayout.java 28 Apr 2003 05:44:33 -0000 1.1
+++ XMLLayout.java 29 Apr 2003 16:21:30 -0000 1.2
@@ -51,16 +51,13 @@
// Contributors: Mathias Bogaert
package org.apache.log4j.xml;
+import java.util.Iterator;
+import java.util.Set;
+
import org.apache.log4j.Layout;
import org.apache.log4j.helpers.Transform;
import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org