Package org.apache.log4j.receivers.net
Class MulticastAppender
- java.lang.Object
-
- org.apache.log4j.AppenderSkeleton
-
- org.apache.log4j.receivers.net.MulticastAppender
-
- All Implemented Interfaces:
org.apache.log4j.Appender
,NetworkBased
,PortBased
,org.apache.log4j.spi.OptionHandler
public class MulticastAppender extends org.apache.log4j.AppenderSkeleton implements PortBased
Multicast-based Appender. Works in conjunction with the MulticastReceiver, which expects a LoggingEvent encoded using XMLLayout. Sends log information as a multicast datagrams.Messages are not sent as LoggingEvent objects but as text after applying XMLLayout.
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.
This was inspired and really extended/copied from
SocketAppender
. Please see the docs for the proper credit to the authors of that class.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.net.InetAddress
address
private boolean
advertiseViaMulticastDNS
(package private) java.lang.String
application
(package private) static int
DEFAULT_PORT
The default port number for the multicast packets.private java.lang.String
encoding
(package private) java.lang.String
hostname
We remember host name as String in addition to the resolved InetAddress so that it can be returned via getOption().private boolean
locationInfo
(package private) java.net.MulticastSocket
outSocket
(package private) int
port
(package private) java.lang.String
remoteHost
(package private) int
timeToLive
private org.apache.log4j.net.ZeroConfSupport
zeroConf
static java.lang.String
ZONE
The MulticastDNS zone advertised by a MulticastAppender the MulticastAppender also adds a 'multicastAddress' property with the multicast address value as a string
-
Constructor Summary
Constructors Constructor Description MulticastAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateOptions()
Open the multicast sender for the RemoteHost and Port.void
append(org.apache.log4j.spi.LoggingEvent event)
void
cleanUp()
Close the Socket and release the underlying connector thread if it has been createdvoid
close()
Close this appender.(package private) void
connect()
(package private) java.net.InetAddress
getAddressByName(java.lang.String host)
java.lang.String
getApplication()
Returns value of the App option.java.lang.String
getEncoding()
Returns value of the Encoding option.boolean
getLocationInfo()
Returns value of the LocationInfo option.int
getPort()
Returns value of the Port option.java.lang.String
getRemoteHost()
Returns value of the RemoteHost option.int
getTimeToLive()
Returns value of the Time to Live option.boolean
isActive()
Get if item is active.boolean
isAdvertiseViaMulticastDNS()
boolean
requiresLayout()
Gets whether appender requires a layout.void
setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
void
setApplication(java.lang.String app)
The App option takes a string value which should be the name of the application getting logged.void
setEncoding(java.lang.String encoding)
The Encoding option specifies how the bytes are encoded.void
setLocationInfo(boolean locationInfo)
The LocationInfo option takes a boolean value.void
setPort(int port)
The Port option takes a positive integer representing the port where multicast packets will be sent.void
setRemoteHost(java.lang.String host)
The RemoteHost option takes a string value which should be the host name or ipaddress to send the multicast packets.void
setTimeToLive(int timeToLive)
The Time to live option takes a positive integer representing the time to live value.-
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.log4j.receivers.net.NetworkBased
getName
-
-
-
-
Field Detail
-
DEFAULT_PORT
static final int DEFAULT_PORT
The default port number for the multicast packets. (9991).- See Also:
- Constant Field Values
-
ZONE
public static final java.lang.String ZONE
The MulticastDNS zone advertised by a MulticastAppender the MulticastAppender also adds a 'multicastAddress' property with the multicast address value as a string- See Also:
- Constant Field Values
-
hostname
java.lang.String hostname
We remember host name as String in addition to the resolved InetAddress so that it can be returned via getOption().
-
remoteHost
java.lang.String remoteHost
-
application
java.lang.String application
-
timeToLive
int timeToLive
-
address
java.net.InetAddress address
-
port
int port
-
outSocket
java.net.MulticastSocket outSocket
-
encoding
private java.lang.String encoding
-
locationInfo
private boolean locationInfo
-
advertiseViaMulticastDNS
private boolean advertiseViaMulticastDNS
-
zeroConf
private org.apache.log4j.net.ZeroConfSupport zeroConf
-
-
Method Detail
-
activateOptions
public void activateOptions()
Open the multicast sender for the RemoteHost and Port.- Specified by:
activateOptions
in interfaceorg.apache.log4j.spi.OptionHandler
- Overrides:
activateOptions
in classorg.apache.log4j.AppenderSkeleton
-
close
public void close()
Close this appender.This will mark the appender as closed and call then
cleanUp()
method.- Specified by:
close
in interfaceorg.apache.log4j.Appender
-
cleanUp
public void cleanUp()
Close the Socket and release the underlying connector thread if it has been created
-
connect
void connect()
-
append
public void append(org.apache.log4j.spi.LoggingEvent event)
- Specified by:
append
in classorg.apache.log4j.AppenderSkeleton
-
getAddressByName
java.net.InetAddress getAddressByName(java.lang.String host)
-
setRemoteHost
public void setRemoteHost(java.lang.String host)
The RemoteHost option takes a string value which should be the host name or ipaddress to send the multicast packets.
-
getRemoteHost
public java.lang.String getRemoteHost()
Returns value of the RemoteHost option.
-
setLocationInfo
public void setLocationInfo(boolean locationInfo)
The LocationInfo option takes a boolean value. If true, the information sent to the remote host will include location information. By default no location information is sent to the server.
-
getLocationInfo
public boolean getLocationInfo()
Returns value of the LocationInfo option.
-
setEncoding
public void setEncoding(java.lang.String encoding)
The Encoding option specifies how the bytes are encoded. If this option is not specified, the System encoding is used.
-
getEncoding
public java.lang.String getEncoding()
Returns value of the Encoding option.
-
setApplication
public void setApplication(java.lang.String app)
The App 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.
-
getApplication
public java.lang.String getApplication()
Returns value of the App option.
-
setTimeToLive
public void setTimeToLive(int timeToLive)
The Time to live option takes a positive integer representing the time to live value.
-
getTimeToLive
public int getTimeToLive()
Returns value of the Time to Live option.
-
setPort
public void setPort(int port)
The Port option takes a positive integer representing the port where multicast packets will be sent.
-
getPort
public int getPort()
Returns value of the Port option.
-
isActive
public boolean isActive()
Description copied from interface:NetworkBased
Get if item is active.- Specified by:
isActive
in interfaceNetworkBased
- Returns:
- if true, item is active.
-
requiresLayout
public boolean requiresLayout()
Gets whether appender requires a layout.- Specified by:
requiresLayout
in interfaceorg.apache.log4j.Appender
- Returns:
- false
-
isAdvertiseViaMulticastDNS
public boolean isAdvertiseViaMulticastDNS()
-
setAdvertiseViaMulticastDNS
public void setAdvertiseViaMulticastDNS(boolean advertiseViaMulticastDNS)
-
-