Package org.apache.log4j.net
Class XMLSocketReceiver
- java.lang.Object
-
- org.apache.log4j.spi.ComponentBase
-
- org.apache.log4j.plugins.PluginSkeleton
-
- org.apache.log4j.plugins.Receiver
-
- org.apache.log4j.net.XMLSocketReceiver
-
- All Implemented Interfaces:
Runnable
,NetworkBased
,PortBased
,Pauseable
,Plugin
,Component
,org.apache.log4j.spi.OptionHandler
,Thresholdable
public class XMLSocketReceiver extends Receiver implements Runnable, PortBased, Pauseable
XMLSocketReceiver receives a remote logging event via XML on a configured socket and "posts" it to a LoggerRepository as if the event were generated locally. This class is designed to receive events from the XMLSocketAppender class (or classes that send compatible events).This receiver supports log files created using log4j's XMLLayout, as well as java.util.logging XMLFormatter (via the org.apache.log4j.spi.Decoder interface).
By default, log4j's XMLLayout is supported (no need to specify a decoder in that case).
To configure this receiver to support java.util.logging's XMLFormatter, specify a 'decoder' param of org.apache.log4j.xml.UtilLoggingXMLDecoder.
Once the event has been "posted", it will be handled by the appenders currently configured in the LoggerRespository.
- Author:
- Mark Womack, Scott Deboy <sdeboy@apache.org>
-
-
Field Summary
Fields Modifier and Type Field Description protected String
decoder
static int
DEFAULT_PORT
protected int
port
static String
ZONE
The MulticastDNS zone advertised by an XMLSocketReceiver-
Fields inherited from class org.apache.log4j.plugins.Receiver
thresholdLevel
-
Fields inherited from class org.apache.log4j.plugins.PluginSkeleton
active, name
-
Fields inherited from class org.apache.log4j.spi.ComponentBase
repository
-
-
Constructor Summary
Constructors Constructor Description XMLSocketReceiver()
XMLSocketReceiver(int _port)
XMLSocketReceiver(int _port, org.apache.log4j.spi.LoggerRepository _repository)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateOptions()
Starts the XMLSocketReceiver with the current options.void
doPost(org.apache.log4j.spi.LoggingEvent event)
Posts the logging event to a logger in the configured logger repository.String
getDecoder()
int
getPort()
Get the port to receive logging events on.int
hashCode()
boolean
isAdvertiseViaMulticastDNS()
boolean
isEquivalent(Plugin testPlugin)
Returns true if the receiver is the same class and they are configured for the same properties, and super class also considers them to be equivalent.boolean
isPaused()
Get paused state.void
run()
Loop, accepting new socket connections.protected void
setActive(boolean b)
Sets the flag to indicate if receiver is active or not.void
setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
void
setDecoder(String _decoder)
Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file.void
setPaused(boolean b)
Set paused state.void
setPort(int _port)
Set the port to receive logging events on.void
shutdown()
Called when the receiver should be stopped.-
Methods inherited from class org.apache.log4j.plugins.Receiver
getThreshold, isAsSevereAsThreshold, setThreshold
-
Methods inherited from class org.apache.log4j.plugins.PluginSkeleton
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getLoggerRepository, getName, isActive, removePropertyChangeListener, removePropertyChangeListener, setLoggerRepository, setName
-
Methods inherited from class org.apache.log4j.spi.ComponentBase
getLogger, getNonFloodingLogger, resetErrorCount
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.log4j.net.NetworkBased
getName, isActive
-
-
-
-
Field Detail
-
decoder
protected String decoder
-
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
port
protected int port
-
ZONE
public static final String ZONE
The MulticastDNS zone advertised by an XMLSocketReceiver- See Also:
- Constant Field Values
-
-
Method Detail
-
getPort
public int getPort()
Get the port to receive logging events on.
-
setPort
public void setPort(int _port)
Set the port to receive logging events on.
-
getDecoder
public String getDecoder()
-
setDecoder
public void setDecoder(String _decoder)
Specify the class name implementing org.apache.log4j.spi.Decoder that can process the file.
-
isPaused
public boolean isPaused()
Description copied from interface:Pauseable
Get paused state.
-
setPaused
public void setPaused(boolean b)
Description copied from interface:Pauseable
Set paused state.
-
isEquivalent
public boolean isEquivalent(Plugin testPlugin)
Returns true if the receiver is the same class and they are configured for the same properties, and super class also considers them to be equivalent. This is used by PluginRegistry when determining if the a similarly configured receiver is being started.- Specified by:
isEquivalent
in interfacePlugin
- Overrides:
isEquivalent
in classPluginSkeleton
- Parameters:
testPlugin
- The plugin to test equivalency against.- Returns:
- boolean True if the testPlugin is equivalent to this plugin.
-
setActive
protected void setActive(boolean b)
Sets the flag to indicate if receiver is active or not.- Parameters:
b
- new value
-
activateOptions
public void activateOptions()
Starts the XMLSocketReceiver with the current options.- Specified by:
activateOptions
in interfaceorg.apache.log4j.spi.OptionHandler
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
-
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS()
-
shutdown
public void shutdown()
Called when the receiver should be stopped. Closes the server socket and all of the open sockets.
-
run
public void run()
Loop, accepting new socket connections.
-
-