Top Description Inners Fields Constructors Methods
org.jboss.logmanager.handlers

public Class SyslogHandler

extends ExtHandler
Class Inheritance
Annotations
@SuppressWarnings:WeakerAccess, unused
Static Imports
java.security.AccessController.doPrivileged, java.time.temporal.ChronoField.DAY_OF_MONTH, .ChronoField.HOUR_OF_DAY, .ChronoField.MILLI_OF_SECOND, .ChronoField.MINUTE_OF_HOUR, .ChronoField.MONTH_OF_YEAR, .ChronoField.SECOND_OF_MINUTE, .ChronoField.YEAR

A syslog handler for logging to syslogd.

This handler can write to syslog servers that accept the RFC3164 and RFC5424 formats. Writes can be done via TCP, SSL over TCP or UDP protocols. You can also override the output stream if a custom protocol is needed.

 
Configuration Properties:
Property Description Type Default
serverHostname The address of the syslog server String localhost
port The port of the syslog server int 514
facility The facility used to calculate the priority of the log message Facility USER_LEVEL
appName The name of the application that is logging String java
hostname The name of the host the messages are being sent from. See setHostname(String) for more details String null
syslogType The type of the syslog used to format the message SyslogType RFC5424
protocol The protocol to send the message over Protocol UDP
delimiter The delimiter to use at the end of the message if useDelimiter is set to true String For UDP null - For TCP or SSL_TCP \n
useDelimiter Whether or not the message should be appended with a delimiter boolean For UDP false - For TCP or SSL_TCP true
useCountingFraming Prefixes the size of the message, mainly used for TCP or SSL_TCP, connections to the message being sent to the syslog server. See http://tools.ietf.org/html/rfc6587 for more details on framing types. boolean false
truncate Whether or not a message, including the header, should truncate the message if the length in bytes is greater than the maximum length. If set to false messages will be split and sent with the same header values. boolean true
maxLength The maximum length a log message, including the header, is allowed to be. int For RFC3164 1024 (1k) - For RFC5424 2048 (2k)

Author
James R. Perkins

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
public static enum
SyslogHandler.Protocol

The type of socket the syslog should write to

public static enum
public static enum
SyslogHandler.SyslogType

The syslog type used for formatting the message.

Field Summary

Modifier and TypeField and Description
private String
private boolean
private ClientSocketFactory
public static final InetAddress
public static final String
public static final SyslogHandler.Facility
public static final int
public static final int
private String
private SyslogHandler.Facility
private String
private boolean
private int
public static final String
private OutputStream
private boolean
private int
private static final Pattern
private SyslogHandler.Protocol
private static final DateTimeFormatter
private static final DateTimeFormatter
private InetAddress
private SyslogHandler.SyslogType
private boolean
private boolean
private boolean
Inherited from org.jboss.logmanager.ExtHandler:
handlershandlersUpdaterlock

Constructor Summary

AccessConstructor and Description
public
SyslogHandler()

The default class constructor.

public
SyslogHandler(final String
the server to send the messages to
serverHostname
,
final int
the port the syslogd is listening on
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.

public
SyslogHandler(final InetAddress
the server to send the messages to
serverAddress
,
final int
the port the syslogd is listening on
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.

public
SyslogHandler(final String
the server to send the messages to
serverHostname
,
final int
the port the syslogd is listening on
port
,
final SyslogHandler.Facility
the facility to use when calculating priority
facility
,
final String
the name of the host the messages are being sent from see setHostname(String) for details on the hostname
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.

public
SyslogHandler(final InetAddress
the server to send the messages to
serverAddress
,
final int
the port the syslogd is listening on
port
,
final SyslogHandler.Facility
the facility to use when calculating priority
facility
,
final String
the name of the host the messages are being sent from see setHostname(String) for details on the hostname
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.

public
SyslogHandler(final String
the server to send the messages to
serverHostname
,
final int
the port the syslogd is listening on
port
,
final SyslogHandler.Facility
the facility to use when calculating priority
facility
,
final SyslogHandler.SyslogType
the type of the syslog used to format the message
syslogType
,
final String
the name of the host the messages are being sent from see setHostname(String) for details on the hostname
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.

public
SyslogHandler(final InetAddress
the server to send the messages to
serverAddress
,
final int
the port the syslogd is listening on
port
,
final SyslogHandler.Facility
the facility to use when calculating priority
facility
,
final SyslogHandler.SyslogType
the type of the syslog used to format the message
syslogType
,
final String
the name of the host the messages are being sent from see setHostname(String) for details on the hostname
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.

public
SyslogHandler(final String
the server to send the messages to
serverHostname
,
final int
the port the syslogd is listening on
port
,
final SyslogHandler.Facility
the facility to use when calculating priority
facility
,
final SyslogHandler.SyslogType
the type of the syslog used to format the message
syslogType
,
final SyslogHandler.Protocol
the socket type used to the connect to the syslog server
protocol
,
final String
the name of the host the messages are being sent from see setHostname(String) for details on the hostname
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.

public
SyslogHandler(final InetAddress
the server to send the messages to
serverAddress
,
final int
the port the syslogd is listening on
port
,
final SyslogHandler.Facility
the facility to use when calculating priority
facility
,
final SyslogHandler.SyslogType
the type of the syslog used to format the message
syslogType
,
final SyslogHandler.Protocol
the socket type used to the connect to the syslog server
protocol
,
final String
the name of the host the messages are being sent from see setHostname(String) for details on the hostname
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

Modifier and TypeMethod and Description
protected int
calculatePriority(final Level level, final SyslogHandler.Facility facility)

private static String
checkPrintableAscii(final String name, final String value)

public void
close()

Overrides org.jboss.logmanager.ExtHandler.close.

Implements java.lang.AutoCloseable.close.

Close all child handlers.

protected byte[]
protected byte[]
public final void
doPublish(final ExtLogRecord
the log record to publish
record
)

Overrides org.jboss.logmanager.ExtHandler.doPublish.

Do the actual work of publication; the record will have been filtered already.

public void
flush()

Overrides org.jboss.logmanager.ExtHandler.flush.

Implements java.io.Flushable.flush.

Flush all child handlers.

public String

Returns:

the app name being used
getAppName
()

Gets app name used when formatting the message in RFC5424 format.

private ClientSocketFactory
public SyslogHandler.Facility

Returns:

the facility
getFacility
()

Returns the facility used for calculating the priority of the message.

public String

Returns:

the host name
getHostname
()

Returns the host name which is used when sending the message to the syslog.

public int

Returns:

the maximum length, in bytes, of the message allowed to be sent
getMaxLength
()

Returns the maximum length, in bytes, of the message allowed to be sent.

public String

Returns:

the delimiter being used for the message
getMessageDelimiter
()

Returns the delimiter being used for the message if use message delimiter is set to true.

public String

Returns:

the pid or null if the pid could not be determined
getPid
()
Deprecated for removal since 3.1. Always returns the current process ID, as a string.

Returns the pid being used as the PROCID for RFC5424 messages.

public int

Returns:

the port
getPort
()

Returns the port the syslogd is listening on.

public SyslogHandler.Protocol

Returns:

the protocol
getProtocol
()

The protocol used to connect to the syslog server

public InetAddress

Returns:

the server address
getServerAddress
()

Returns the server address the messages are being sent to.

public SyslogHandler.SyslogType

Returns:

the syslog type
getSyslogType
()

Returns the syslog type this handler is using to format the message sent.

private void
init()

public boolean

Returns:

true if blocking is enabled, otherwise false
isBlockOnReconnect
()

Indicates whether or not a TCP or SSL TCP connection should block when attempting to reconnect.

public boolean

Returns:

false
isEscapeEnabled
()
Deprecated escaping message values is not required per RFC5424 and is no longer supported in this handler

Checks whether or not characters below decimal 32, traditional US-ASCII control values expect DEL, are being escaped or not.

public boolean

Returns:

true if the message should be truncated if too large, otherwise false
isTruncate
()

Checks if the message should truncated if the total length exceeds the maximum length.

public boolean

Returns:

the message transfer type
isUseCountingFraming
()

Returns true if the message size should be prefixed to the message being sent.

public boolean

Returns:

true to append the message with a delimiter, otherwise false
isUseMessageDelimiter
()

Checks whether to append the message with a delimiter or not.

pack-priv static void
safeClose(final Closeable closeable)

pack-priv static void
safeFlush(final Flushable flushable)

private void
sendMessage(final byte[] header, final ByteStringBuilder
the message to write
message
,
final byte[] trailer)

Writes the message to the output stream.

public void
setAppName(final String
the app name to use
appName
)

Sets app name used when formatting the message in RFC5424 format.

public void
setBlockOnReconnect(final boolean
true to block when reconnecting or false to reconnect asynchronously discarding any new messages coming in
blockOnReconnect
)

Enables or disables blocking when attempting to reconnect a TCP or SSL TCP protocol.

public void
setClientSocketFactory(final ClientSocketFactory
the client socket factory to use
clientSocketFactory
)

Sets the client socket factory used to create sockets.

public void
setEscapeEnabled(final boolean
true to escape characters, false to not escape characters
escapeEnabled
)
Deprecated escaping message values is not required per RFC5424 and is no longer supported in this handler

Set to true to escape characters within the message string that are below decimal 32.

public void
setFacility(final SyslogHandler.Facility
the facility
facility
)

Sets the facility used when calculating the priority of the message.

public void
setHostname(final String
the host name
hostname
)

Sets the host name which is used when sending the message to the syslog.

public void
setMaxLength(final int
the maximum length, in bytes, allowed to be sent to the syslog server
maxLen
)

Sets the maximum length, in bytes, of the message allowed to tbe sent.

public void
setMessageDelimiter(final String
the delimiter to use for the message
delimiter
)

Sets the message delimiter to be used if use message delimiter is set to true.

public void
setOutputStream(final OutputStream
the output stream to write to
out
)

Sets the output stream for the syslog handler to write to.

private void
setOutputStream(final OutputStream out, final boolean outputStreamSet)

public void
setPort(final int
the port
port
)

Sets the port the syslogd server is listening on.

public void
setProtocol(final SyslogHandler.Protocol
the protocol
type
)

Sets the protocol used to connect to the syslog server

public void
setServerAddress(final InetAddress
the server address
serverAddress
)

Sets the server address the messages should be sent to.

public void
setServerHostname(final String
the hostname used to created the connection
hostname
)

Sets the server address the messages should be sent to.

public void
setSyslogType(final SyslogHandler.SyslogType
the syslog type
syslogType
)

Set the syslog type this handler should use to format the message sent.

public void
setTruncate(final boolean
true to truncate, otherwise false to send multiple messages
truncate
)

Set to true if the message should be truncated if the total length the maximum length.

public void
setUseCountingFraming(final boolean
true if the message being sent should be prefixed with the size of the message
useCountingFraming
)

Set to true if the message being sent should be prefixed with the size of the message.

public void
setUseMessageDelimiter(final boolean
true to append the message with a delimiter, otherwise false
useDelimiter
)

Whether to append the message with a delimiter or not.

Inherited from org.jboss.logmanager.ExtHandler:
addHandlercheckAccesscheckAccessclearHandlersgetCharsetgetEncodinggetErrorManagergetFiltergetFormattergetHandlersgetLevelisAutoFlushisCallerCalculationRequiredisCloseChildrenisEnabledpublishpublishpublishToNestedHandlersremoveHandlerreportErrorreportErrorsetAutoFlushsetCharsetsetCharsetPrivatesetCloseChildrensetEnabledsetEncodingsetErrorManagersetFiltersetFormattersetHandlerssetLevel