public class SyslogHandler extends ExtHandler
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) |
Modifier and Type | Class and Description |
---|---|
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.Protocol
The type of socket the syslog should write to
|
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.
|
Modifier and Type | Field and Description |
---|---|
static InetAddress |
DEFAULT_ADDRESS |
static String |
DEFAULT_ENCODING |
static SyslogHandler.Facility |
DEFAULT_FACILITY |
static int |
DEFAULT_PORT |
static int |
DEFAULT_SECURE_PORT |
static String |
NILVALUE_SP |
handlers, handlersUpdater
Constructor and Description |
---|
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(InetAddress serverAddress,
int port,
SyslogHandler.Facility facility,
SyslogHandler.SyslogType syslogType,
SyslogHandler.Protocol protocol,
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. |
SyslogHandler(String serverHostname,
int port,
SyslogHandler.Facility facility,
SyslogHandler.SyslogType syslogType,
SyslogHandler.Protocol protocol,
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. |
Modifier and Type | Method and Description |
---|---|
protected int |
calculatePriority(Level level,
SyslogHandler.Facility facility) |
void |
close()
Close all child handlers.
|
protected byte[] |
createRFC3164Header(ExtLogRecord record) |
protected byte[] |
createRFC5424Header(ExtLogRecord record) |
void |
doPublish(ExtLogRecord record)
Do the actual work of publication; the record will have been filtered already.
|
void |
flush()
Flush all child handlers.
|
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.
|
int |
getMaxLength()
Returns the maximum length, in bytes, of the message allowed to be sent.
|
String |
getMessageDelimiter()
Returns the delimiter being used for the message if
use message
delimiter is set to true . |
String |
getPid()
Returns the pid being used as the PROCID for RFC5424 messages.
|
int |
getPort()
Returns the port the syslogd is listening on.
|
SyslogHandler.Protocol |
getProtocol()
The protocol used to connect to the syslog server
|
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. |
boolean |
isBlockOnReconnect()
|
boolean |
isEscapeEnabled()
Deprecated.
escaping message values is not required per RFC5424
and is no longer supported in this handler
|
boolean |
isTruncate()
Checks if the message should truncated if the total length exceeds the
maximum length . |
boolean |
isUseCountingFraming()
Returns
true if the message size should be prefixed to the message being sent. |
boolean |
isUseMessageDelimiter()
Checks whether to append the message with a delimiter or not.
|
void |
setAppName(String appName)
Sets app name used when formatting the message in RFC5424 format.
|
void |
setBlockOnReconnect(boolean blockOnReconnect)
|
void |
setEscapeEnabled(boolean escapeEnabled)
Deprecated.
escaping message values is not required per RFC5424
and is no longer supported in this handler
|
void |
setFacility(SyslogHandler.Facility facility)
Sets the facility used when calculating the priority of the message.
|
void |
setHostname(String hostname)
Sets the host name which is used when sending the message to the syslog.
|
void |
setMaxLength(int maxLen)
Sets the maximum length, in bytes, of the message allowed to tbe sent.
|
void |
setMessageDelimiter(String delimiter)
Sets the message delimiter to be used if
use message
delimiter is set to true . |
void |
setOutputStream(OutputStream out)
Sets the output stream for the syslog handler to write to.
|
void |
setPort(int port)
Sets the port the syslogd server is listening on.
|
void |
setProtocol(SyslogHandler.Protocol type)
Sets the protocol used to connect to the syslog server
|
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. |
void |
setTruncate(boolean truncate)
Set to
true if the message should be truncated if the total length the maximum
length . |
void |
setUseCountingFraming(boolean useCountingFraming)
Set to
true if the message being sent should be prefixed with the size of the message. |
void |
setUseMessageDelimiter(boolean useDelimiter)
Whether to append the message with a delimiter or not.
|
addHandler, checkAccess, checkAccess, clearHandlers, disableAccess, enableAccess, getHandlers, isAutoFlush, isCloseChildren, isEnabled, protect, publish, publish, removeHandler, setAutoFlush, setCloseChildren, setEnabled, setEncoding, setErrorManager, setFilter, setFormatter, setHandlers, setLevel, unprotect
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError
public static final InetAddress DEFAULT_ADDRESS
public static final int DEFAULT_PORT
public static final int DEFAULT_SECURE_PORT
public static final String DEFAULT_ENCODING
public static final SyslogHandler.Facility DEFAULT_FACILITY
public static final String NILVALUE_SP
public SyslogHandler() throws IOException
IOException
- if an error occurs creating the UDP socketpublic SyslogHandler(String serverHostname, int port) throws IOException
serverHostname
parameter on the port represented by the port
parameter.serverHostname
- the server to send the messages toport
- the port the syslogd is listening onIOException
- if an error occurs creating the UDP socketpublic SyslogHandler(InetAddress serverAddress, int port) throws IOException
serverAddress
parameter on the port represented by the port
parameter.serverAddress
- the server to send the messages toport
- the port the syslogd is listening onIOException
- if an error occurs creating the UDP socketpublic SyslogHandler(String serverHostname, int port, SyslogHandler.Facility facility, String hostname) throws IOException
serverAddress
parameter on the port represented by the port
parameter.serverHostname
- the server to send the messages toport
- the port the syslogd is listening onfacility
- the facility to use when calculating priorityhostname
- the name of the host the messages are being sent from see setHostname(String)
for
details on the hostnameIOException
- if an error occurs creating the UDP socketpublic SyslogHandler(InetAddress serverAddress, int port, SyslogHandler.Facility facility, String hostname) throws IOException
serverAddress
parameter on the port represented by the port
parameter.serverAddress
- the server to send the messages toport
- the port the syslogd is listening onfacility
- the facility to use when calculating priorityhostname
- the name of the host the messages are being sent from see setHostname(String)
for
details on the hostnameIOException
- if an error occurs creating the UDP socketpublic SyslogHandler(String serverHostname, int port, SyslogHandler.Facility facility, SyslogHandler.SyslogType syslogType, String hostname) throws IOException
serverAddress
parameter on the port represented by the port
parameter.serverHostname
- the server to send the messages toport
- the port the syslogd is listening onfacility
- the facility to use when calculating prioritysyslogType
- the type of the syslog used to format the messagehostname
- the name of the host the messages are being sent from see setHostname(String)
for
details on the hostnameIOException
- if an error occurs creating the UDP socketpublic SyslogHandler(InetAddress serverAddress, int port, SyslogHandler.Facility facility, SyslogHandler.SyslogType syslogType, String hostname) throws IOException
serverAddress
parameter on the port represented by the port
parameter.serverAddress
- the server to send the messages toport
- the port the syslogd is listening onfacility
- the facility to use when calculating prioritysyslogType
- the type of the syslog used to format the messagehostname
- the name of the host the messages are being sent from see setHostname(String)
for
details on the hostnameIOException
- if an error occurs creating the UDP socketpublic SyslogHandler(String serverHostname, int port, SyslogHandler.Facility facility, SyslogHandler.SyslogType syslogType, SyslogHandler.Protocol protocol, String hostname) throws IOException
serverAddress
parameter on the port represented by the port
parameter.serverHostname
- the server to send the messages toport
- the port the syslogd is listening onfacility
- the facility to use when calculating prioritysyslogType
- the type of the syslog used to format the messageprotocol
- the socket type used to the connect to the syslog serverhostname
- the name of the host the messages are being sent from see setHostname(String)
for
details on the hostnameIOException
- if an error occurs creating the UDP socketpublic SyslogHandler(InetAddress serverAddress, int port, SyslogHandler.Facility facility, SyslogHandler.SyslogType syslogType, SyslogHandler.Protocol protocol, String hostname) throws IOException
serverAddress
parameter on the port represented by the port
parameter.serverAddress
- the server to send the messages toport
- the port the syslogd is listening onfacility
- the facility to use when calculating prioritysyslogType
- the type of the syslog used to format the messageprotocol
- the socket type used to the connect to the syslog serverhostname
- the name of the host the messages are being sent from see setHostname(String)
for
details on the hostnameIOException
- if an error occurs creating the UDP socketpublic final void doPublish(ExtLogRecord record)
ExtHandler
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.doPublish
in class ExtHandler
record
- the log record to publishpublic void close()
ExtHandler
close
in interface Closeable
close
in interface AutoCloseable
close
in class ExtHandler
public void flush()
ExtHandler
flush
in interface Flushable
flush
in class ExtHandler
public String getAppName()
public void setAppName(String appName)
appName
- the app name to useSecurityException
- if a security manager exists and if the caller does not have LoggingPermission(control)
or the handler is protected
public boolean isBlockOnReconnect()
true
if blocking is enabled, otherwise false
public void setBlockOnReconnect(boolean blockOnReconnect)
TCP
or SSL TCP
protocol.
If set to true
the publish
methods will block when attempting to reconnect. This is only
advisable to be set to true
if using an asynchronous handler.blockOnReconnect
- true
to block when reconnecting or false
to reconnect asynchronously
discarding any new messages coming in@Deprecated public boolean isEscapeEnabled()
DEL
, are
being escaped or not.false
@Deprecated public void setEscapeEnabled(boolean escapeEnabled)
true
to escape characters within the message string that are below decimal 32. These values are
tradition US-ASCII control values. The values will be replaced in a #xxx
format where xxx
is the
octal value of the character being replaced.escapeEnabled
- true
to escape characters, false
to not escape characterspublic String getPid()
public int getPort()
public void setPort(int port)
port
- the portSecurityException
- if a security manager exists and if the caller does not have LoggingPermission(control)
or the handler is protected
public SyslogHandler.Facility getFacility()
public void setFacility(SyslogHandler.Facility facility)
facility
- the facilitySecurityException
- if a security manager exists and if the caller does not have LoggingPermission(control)
or the handler is protected
public String getHostname()
public int getMaxLength()
public void setMaxLength(int maxLen)
maxLen
- the maximum length, in bytes, allowed to be sent to the syslog serverpublic String getMessageDelimiter()
use message
delimiter
is set to true
.public void setMessageDelimiter(String delimiter)
use message
delimiter
is set to true
.delimiter
- the delimiter to use for the messagepublic boolean isUseMessageDelimiter()
true
to append the message with a delimiter, otherwise false
public void setUseMessageDelimiter(boolean useDelimiter)
useDelimiter
- true
to append the message with a delimiter, otherwise false
public void setHostname(String hostname)
null
hostname
- the host namepublic boolean isUseCountingFraming()
true
if the message size should be prefixed to the message being sent.
See http://tools.ietf.org/html/rfc6587
for more details on framing types.public void setUseCountingFraming(boolean useCountingFraming)
true
if the message being sent should be prefixed with the size of the message.
See http://tools.ietf.org/html/rfc6587
for more details on framing types.useCountingFraming
- true
if the message being sent should be prefixed with the size of the messageSecurityException
- if a security manager exists and if the caller does not have LoggingPermission(control)
or the handler is protected
public void setServerHostname(String hostname) throws UnknownHostException
hostname
- the hostname used to created the connectionUnknownHostException
- 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
InetAddress.getByName(String)
public InetAddress getServerAddress()
public void setServerAddress(InetAddress serverAddress)
serverAddress
- the server addressSecurityException
- if a security manager exists and if the caller does not have LoggingPermission(control)
or the handler is protected
public SyslogHandler.SyslogType getSyslogType()
syslog type
this handler is using to format the message sent.public void setSyslogType(SyslogHandler.SyslogType syslogType)
syslog type
this handler should use to format the message sent.syslogType
- the syslog typeSecurityException
- if a security manager exists and if the caller does not have LoggingPermission(control)
or the handler is protected
public SyslogHandler.Protocol getProtocol()
public void setProtocol(SyslogHandler.Protocol type)
type
- the protocolpublic void setOutputStream(OutputStream out)
null
. The protocol
, #setServerAddress(java.net.InetAddress), server address
, server hostname
or
port
have no effect when the output stream is set.out
- the output stream to write topublic boolean isTruncate()
maximum length
.true
if the message should be truncated if too large, otherwise false
public void setTruncate(boolean truncate)
true
if the message should be truncated if the total length the maximum
length
.
Set to false
if the message should be split and sent as multiple messages. The header will remain the
same for each message sent. The wrapping is not a word based wrap and could split words between log messages.truncate
- true
to truncate, otherwise false
to send multiple messagesprotected int calculatePriority(Level level, SyslogHandler.Facility facility)
protected byte[] createRFC5424Header(ExtLogRecord record) throws IOException
IOException
protected byte[] createRFC3164Header(ExtLogRecord record) throws IOException
IOException
Copyright © 2017 JBoss by Red Hat. All rights reserved.