Skip to content
This repository has been archived by the owner. It is now read-only.

SyslogAppender - support higher and configurable max message size #2

Merged
merged 1 commit into from Apr 22, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

SyslogAppender - support higher and configurable max message size

  • Loading branch information
Vinh Nguyen
Vinh Nguyen committed Apr 22, 2015
commit 3551d59fdbfa849f0ab78acc0d11b33b63102a68
@@ -91,6 +91,14 @@
protected static final int SYSLOG_HOST_OI = 0;
protected static final int FACILITY_OI = 1;

/**
* Max lengths in bytes of a message. Per RFC 5424, size limits are dictated
* by the syslog transport mapping in use. But, the practical upper limit of
* UDP over IPV4 is 65507 (65535 − 8 byte UDP header − 20 byte IP header).
*/
protected static final int LOWER_MAX_MSG_LENGTH = 480;
protected static final int UPPER_MAX_MSG_LENGTH = 65507;

static final String TAB = " ";

// Have LOG_USER as default
@@ -102,6 +110,11 @@
SyslogQuietWriter sqw;
String syslogHost;

/**
* Max length in bytes of a message.
*/
int maxMessageLength = UPPER_MAX_MSG_LENGTH;

/**
* If true, the appender will generate the HEADER (timestamp and host name)
* part of the syslog packet.
@@ -278,12 +291,10 @@ int getFacility(String facilityName) {

private void splitPacket(final String header, final String packet) {
int byteCount = packet.getBytes().length;
//
// if packet is less than RFC 3164 limit
// of 1024 bytes, then write it
// (must allow for up 5to 5 characters in the PRI section
// added by SyslogQuietWriter)
if (byteCount <= 1019) {

// If packet is less than limit, then write it.
// Else, write in chunks.
if (byteCount <= maxMessageLength) {
sqw.write(packet);
} else {
int split = header.length() + (packet.length() - header.length())/2;
@@ -533,4 +544,24 @@ private void sendLayoutMessage(final String msg) {
sqw.write(packet);
}
}

/**
* @return The max message length in bytes.
*/
public int getMaxMessageLength() {
return maxMessageLength;
}

/**
* @param byteLen The max message length in bytes.
*/
public void setMaxMessageLength(int len) {
if (len < LOWER_MAX_MSG_LENGTH || len > UPPER_MAX_MSG_LENGTH) {
System.err.println(len
+ " is an invalid message length. Defaulting to "
+ UPPER_MAX_MSG_LENGTH + ".");
len = UPPER_MAX_MSG_LENGTH;
}
maxMessageLength = len;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.