JBoss Log Manager 1.4.1.Final

org.jboss.logmanager.handlers
Class SyslogHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by org.jboss.logmanager.ExtHandler
          extended by org.jboss.logmanager.handlers.SyslogHandler
All Implemented Interfaces:
Closeable, Flushable, FlushableCloseable, Protectable

public class SyslogHandler
extends ExtHandler

A syslog handler for logging to syslogd.

The log messages are sent via UDP and formatted based on the SyslogHandler.SyslogType. Note that not all settable fields are used on all format types.

Setting formatter has no effect on this handler. The syslog RFC specifications require explicit message formats.

Author:
James R. Perkins

Nested Class Summary
static class SyslogHandler.Facility
          Facility as defined by RFC-5424 (http://tools.ietf.org/html/rfc5424) and RFC-3164 (http://tools.ietf.org/html/rfc3164).
static class SyslogHandler.Severity
          Severity as defined by RFC-5424 (http://tools.ietf.org/html/rfc5424) and RFC-3164 (http://tools.ietf.org/html/rfc3164).
static class SyslogHandler.SyslogType
          The syslog type used for formatting the message.
 
Field Summary
static InetAddress DEFAULT_ADDRESS
           
static SyslogHandler.Facility DEFAULT_FACILITY
           
static int DEFAULT_PORT
           
static char NILVALUE
           
 
Fields inherited from class org.jboss.logmanager.ExtHandler
handlers, handlersUpdater
 
Constructor Summary
SyslogHandler()
          The default class constructor.
SyslogHandler(InetAddress serverAddress, int port)
          Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.
SyslogHandler(InetAddress serverAddress, int port, SyslogHandler.Facility facility, String hostname)
          Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.
SyslogHandler(InetAddress serverAddress, int port, SyslogHandler.Facility facility, SyslogHandler.SyslogType syslogType, String hostname)
          Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.
SyslogHandler(String serverHostname, int port)
          Creates a new syslog handler that sends the messages to the server represented by the serverHostname parameter on the port represented by the port parameter.
SyslogHandler(String serverHostname, int port, SyslogHandler.Facility facility, String hostname)
          Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.
SyslogHandler(String serverHostname, int port, SyslogHandler.Facility facility, SyslogHandler.SyslogType syslogType, String hostname)
          Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.
 
Method Summary
 void close()
          Close all child handlers.
 void doPublish(ExtLogRecord record)
          Do the actual work of publication; the record will have been filtered already.
 String getAppName()
          Gets app name used when formatting the message in RFC5424 format.
 SyslogHandler.Facility getFacility()
          Returns the facility used for calculating the priority of the message.
 String getHostname()
          Returns the host name which is used when sending the message to the syslog.
 String getPid()
          Returns the pid being used as the PROCID for RFC5424 messages.
 int getPort()
          Returns the port the syslogd is listening on.
 InetAddress getServerAddress()
          Returns the server address the messages are being sent to.
 SyslogHandler.SyslogType getSyslogType()
          Returns the syslog type this handler is using to format the message sent.
 void setAppName(String appName)
          Sets app name used when formatting the message in RFC5424 format.
 void setFacility(SyslogHandler.Facility facility)
          Sets the facility used when calculating the priority of the message.
 void setFormatter(Formatter newFormatter)
           
 void setHostname(String hostname)
          Sets the host name which is used when sending the message to the syslog.
 void setPort(int port)
          Sets the port the syslogd server is listening on.
 void setServerAddress(InetAddress serverAddress)
          Sets the server address the messages should be sent to.
 void setServerHostname(String hostname)
          Sets the server address the messages should be sent to.
 void setSyslogType(SyslogHandler.SyslogType syslogType)
          Set the syslog type this handler should use to format the message sent.
 
Methods inherited from class org.jboss.logmanager.ExtHandler
addHandler, checkAccess, checkAccess, clearHandlers, disableAccess, enableAccess, flush, getHandlers, isAutoFlush, isEnabled, protect, publish, publish, removeHandler, setAutoFlush, setEnabled, setEncoding, setErrorManager, setFilter, setHandlers, setLevel, unprotect
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ADDRESS

public static final InetAddress DEFAULT_ADDRESS

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values

DEFAULT_FACILITY

public static final SyslogHandler.Facility DEFAULT_FACILITY

NILVALUE

public static final char NILVALUE
See Also:
Constant Field Values
Constructor Detail

SyslogHandler

public SyslogHandler()
              throws IOException
The default class constructor.

Throws:
IOException - if an error occurs creating the UDP socket

SyslogHandler

public SyslogHandler(String serverHostname,
                     int port)
              throws IOException
Creates a new syslog handler that sends the messages to the server represented by the serverHostname parameter on the port represented by the port parameter.

Parameters:
serverHostname - the server to send the messages to
port - the port the syslogd is listening on
Throws:
IOException - if an error occurs creating the UDP socket

SyslogHandler

public SyslogHandler(InetAddress serverAddress,
                     int port)
              throws IOException
Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.

Parameters:
serverAddress - the server to send the messages to
port - the port the syslogd is listening on
Throws:
IOException - if an error occurs creating the UDP socket

SyslogHandler

public SyslogHandler(String serverHostname,
                     int port,
                     SyslogHandler.Facility facility,
                     String hostname)
              throws IOException
Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.

Parameters:
serverHostname - the server to send the messages to
port - the port the syslogd is listening on
facility - the facility to use when calculating priority
hostname - the name of the host the messages are being sent from
Throws:
IOException - if an error occurs creating the UDP socket

SyslogHandler

public SyslogHandler(InetAddress serverAddress,
                     int port,
                     SyslogHandler.Facility facility,
                     String hostname)
              throws IOException
Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.

Parameters:
serverAddress - the server to send the messages to
port - the port the syslogd is listening on
facility - the facility to use when calculating priority
hostname - the name of the host the messages are being sent from
Throws:
IOException - if an error occurs creating the UDP socket

SyslogHandler

public SyslogHandler(String serverHostname,
                     int port,
                     SyslogHandler.Facility facility,
                     SyslogHandler.SyslogType syslogType,
                     String hostname)
              throws IOException
Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.

Parameters:
serverHostname - the server to send the messages to
port - the port the syslogd is listening on
facility - the facility to use when calculating priority
syslogType - the type of the syslog used to format the message
hostname - the name of the host the messages are being sent from
Throws:
IOException - if an error occurs creating the UDP socket

SyslogHandler

public SyslogHandler(InetAddress serverAddress,
                     int port,
                     SyslogHandler.Facility facility,
                     SyslogHandler.SyslogType syslogType,
                     String hostname)
              throws IOException
Creates a new syslog handler that sends the messages to the server represented by the serverAddress parameter on the port represented by the port parameter.

Parameters:
serverAddress - the server to send the messages to
port - the port the syslogd is listening on
facility - the facility to use when calculating priority
syslogType - the type of the syslog used to format the message
hostname - the name of the host the messages are being sent from
Throws:
IOException - if an error occurs creating the UDP socket
Method Detail

doPublish

public final void doPublish(ExtLogRecord record)
Description copied from class: ExtHandler
Do the actual work of publication; the record will have been filtered already. The default implementation does nothing except to flush if the autoFlush property is set to true; if this behavior is to be preserved in a subclass then this method should be called after the record is physically written.

Overrides:
doPublish in class ExtHandler
Parameters:
record - the log record to publish

close

public void close()
Description copied from class: ExtHandler
Close all child handlers.

Specified by:
close in interface Closeable
Overrides:
close in class ExtHandler

setFormatter

public void setFormatter(Formatter newFormatter)
                  throws SecurityException
Overrides:
setFormatter in class ExtHandler
Throws:
SecurityException

getAppName

public String getAppName()
Gets app name used when formatting the message in RFC5424 format. By default the app name is "java"

Returns:
the app name being used

setAppName

public void setAppName(String appName)
Sets app name used when formatting the message in RFC5424 format. By default the app name is "java"

Parameters:
appName - the app name to use
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control) or the handler is protected

getPid

public String getPid()
Returns the pid being used as the PROCID for RFC5424 messages.

Returns:
the pid

getPort

public int getPort()
Returns the port the syslogd is listening on.

Returns:
the port

setPort

public void setPort(int port)
Sets the port the syslogd server is listening on.

Parameters:
port - the port
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control) or the handler is protected

getFacility

public SyslogHandler.Facility getFacility()
Returns the facility used for calculating the priority of the message.

Returns:
the facility

setFacility

public void setFacility(SyslogHandler.Facility facility)
Sets the facility used when calculating the priority of the message.

Parameters:
facility - the facility
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control) or the handler is protected

getHostname

public String getHostname()
Returns the host name which is used when sending the message to the syslog.

Returns:
the host name

setHostname

public void setHostname(String hostname)
Sets the host name which is used when sending the message to the syslog.

This should be the name of the host sending the log messages, Note that the name cannot contain any whitespace.

Parameters:
hostname - the host name

setServerHostname

public void setServerHostname(String hostname)
                       throws UnknownHostException
Sets the server address the messages should be sent to.

Parameters:
hostname - the hostname used to created the connection
Throws:
UnknownHostException - if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address.
SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control) or the handler is protected
See Also:
InetAddress.getByName(String)

getServerAddress

public InetAddress getServerAddress()
Returns the server address the messages are being sent to.

Returns:
the server address

setServerAddress

public void setServerAddress(InetAddress serverAddress)
Sets the server address the messages should be sent to.

Parameters:
serverAddress - the server address
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control) or the handler is protected

getSyslogType

public SyslogHandler.SyslogType getSyslogType()
Returns the syslog type this handler is using to format the message sent.

Returns:
the syslog type

setSyslogType

public void setSyslogType(SyslogHandler.SyslogType syslogType)
Set the syslog type this handler should use to format the message sent.

Parameters:
syslogType - the syslog type
Throws:
SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control) or the handler is protected

JBoss Log Manager 1.4.1.Final

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.