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
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
protected String
static final int
private boolean
protected int
private Thread
private ServerSocket
private org.apache.log4j.net.ZeroConfSupport
static final String
The MulticastDNS zone advertised by an XMLSocketReceiverFields 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
ConstructorsConstructorDescriptionXMLSocketReceiver
(int _port) XMLSocketReceiver
(int _port, org.apache.log4j.spi.LoggerRepository _repository) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Starts the XMLSocketReceiver with the current options.private void
Closes all the connected sockets in the List.private void
Closes the server socket, if created.void
doPost
(org.apache.log4j.spi.LoggingEvent event) Posts the logging event to a logger in the configured logger repository.private void
Does the actual shutting down by closing the server socket and any connected sockets that have been created.int
getPort()
Get the port to receive logging events on.int
hashCode()
boolean
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 Details
-
paused
private boolean paused -
decoder
-
serverSocket
-
socketList
-
rThread
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
-
port
protected int port -
advertiseViaMulticastDNS
private boolean advertiseViaMulticastDNS -
zeroConf
private org.apache.log4j.net.ZeroConfSupport zeroConf -
ZONE
The MulticastDNS zone advertised by an XMLSocketReceiver- See Also:
-
-
Constructor Details
-
XMLSocketReceiver
public XMLSocketReceiver() -
XMLSocketReceiver
public XMLSocketReceiver(int _port) -
XMLSocketReceiver
public XMLSocketReceiver(int _port, org.apache.log4j.spi.LoggerRepository _repository)
-
-
Method Details
-
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
-
setDecoder
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
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.
-
hashCode
public int hashCode() -
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. -
doShutdown
private void doShutdown()Does the actual shutting down by closing the server socket and any connected sockets that have been created. -
closeServerSocket
private void closeServerSocket()Closes the server socket, if created. -
closeAllAcceptedSockets
private void closeAllAcceptedSockets()Closes all the connected sockets in the List. -
run
public void run()Loop, accepting new socket connections. -
doPost
public void doPost(org.apache.log4j.spi.LoggingEvent event) Description copied from class:Receiver
Posts the logging event to a logger in the configured logger repository.
-