Log4j 1.3alpha-1

org.apache.log4j.net
Class MulticastAppender

java.lang.Object
  |
  +--org.apache.log4j.AppenderSkeleton
        |
        +--org.apache.log4j.net.MulticastAppender
All Implemented Interfaces:
Appender, NetworkBased, OptionHandler, PortBased

public class MulticastAppender
extends 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.

Author:
Kevin Brown, Scott Deboy

Field Summary
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
MulticastAppender()
           
MulticastAppender(java.net.InetAddress address, int port)
          Sends multicast packets to the address and port.
MulticastAppender(java.lang.String host, int port)
          Sends multicast packets to the address and port.
 
Method Summary
 void activateOptions()
          Open the multicast sender for the RemoteHost and Port.
 void append(LoggingEvent event)
          Subclasses of AppenderSkeleton should implement this method to perform actual logging.
 void cleanUp()
          Close the Socket and release the underlying connector thread if it has been created
 void close()
          Close this appender.
 java.lang.String getApplication()
          Returns value of the App option.
 java.lang.String getEncoding()
          Returns value of the Encoding option.
 java.lang.String getOverrideProperties()
          Returns value of the OverrideProperties 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()
           
 boolean requiresLayout()
          The MulticastAppender uses layouts (should be configured with XMLLayout to use MulticastReceiver.
 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 setOverrideProperties(java.lang.String overrideProperties)
          The OverrideProperties option allows configurations where the appender does not apply the machinename/appname properties - the properties will be used as provided.
 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, getLogger, 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.net.NetworkBased
getName
 

Constructor Detail

MulticastAppender

public MulticastAppender()

MulticastAppender

public MulticastAppender(java.net.InetAddress address,
                         int port)
Sends multicast packets to the address and port.


MulticastAppender

public MulticastAppender(java.lang.String host,
                         int port)
Sends multicast packets to the address and port.

Method Detail

activateOptions

public void activateOptions()
Open the multicast sender for the RemoteHost and Port.

Specified by:
activateOptions in interface OptionHandler
Overrides:
activateOptions in class AppenderSkeleton

close

public void close()
Close this appender.

This will mark the appender as closed and call then cleanUp() method.

Specified by:
close in interface Appender

cleanUp

public void cleanUp()
Close the Socket and release the underlying connector thread if it has been created


append

public void append(LoggingEvent event)
Description copied from class: AppenderSkeleton
Subclasses of AppenderSkeleton should implement this method to perform actual logging. See also AppenderSkeleton.doAppend method.

Specified by:
append in class AppenderSkeleton

requiresLayout

public boolean requiresLayout()
The MulticastAppender uses layouts (should be configured with XMLLayout to use MulticastReceiver. Hence, this method returns true.


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.


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.


setOverrideProperties

public void setOverrideProperties(java.lang.String overrideProperties)
The OverrideProperties option allows configurations where the appender does not apply the machinename/appname properties - the properties will be used as provided.


getOverrideProperties

public java.lang.String getOverrideProperties()
Returns value of the OverrideProperties 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.

Specified by:
getPort in interface PortBased
Returns:
int port number

isActive

public boolean isActive()
Specified by:
isActive in interface NetworkBased

Log4j 1.3alpha-1

Copyright 2000-2003 Apache Software Foundation.