Skip to content

Commit

Permalink
[LOGMGR-152] Use new fields in syslog handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Apr 24, 2017
1 parent 987b3f2 commit b3bd0bf
Showing 1 changed file with 45 additions and 19 deletions.
64 changes: 45 additions & 19 deletions src/main/java/org/jboss/logmanager/handlers/SyslogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1190,24 +1190,35 @@ protected byte[] createRFC5424Header(final ExtLogRecord record) throws IOExcepti
buffer.append(' ');
}
// Set the host name
if (hostname == null) {
buffer.append(NILVALUE_SP);
} else {
final String recordHostName = record.getHostName();
if (hostname != null) {
buffer.appendUSASCII(hostname, 255).append(' ');
} else if (recordHostName != null) {
buffer.appendUSASCII(recordHostName, 255).append(' ');
} else {
buffer.append(NILVALUE_SP);
}
// Set the app name
if (appName == null) {
buffer.appendUSASCII(NILVALUE_SP);
} else {
final String recordProcName = record.getProcessName();
if (appName != null) {
buffer.appendUSASCII(appName, 48);
buffer.append(' ');
} else if (recordProcName != null) {
buffer.appendUSASCII(recordProcName, 48);
buffer.append(' ');
} else {
buffer.appendUSASCII(NILVALUE_SP);
}
// Set the procid
if (pid == null) {
buffer.appendUSASCII(NILVALUE_SP);
} else {
final long recordProcId = record.getProcessId();
if (pid != null) {
buffer.appendUSASCII(pid, 128);
buffer.append(' ');
} else if (recordProcId != -1) {
buffer.append(recordProcId);
buffer.append(' ');
} else {
buffer.appendUSASCII(NILVALUE_SP);
}
// Set the msgid
final String msgid = record.getLoggerName();
Expand Down Expand Up @@ -1265,19 +1276,34 @@ protected byte[] createRFC3164Header(final ExtLogRecord record) throws IOExcepti
buffer.append(' ');

// Set the host name
if (hostname == null) {
// TODO might not be the best solution
buffer.appendUSASCII("UNKNOWN_HOSTNAME").append(' ');
} else {
final String recordHostName = record.getHostName();
if (hostname != null) {
buffer.appendUSASCII(hostname).append(' ');
} else if (recordHostName != null) {
buffer.appendUSASCII(recordHostName).append(' ');
} else {
buffer.appendUSASCII("UNKNOWN_HOSTNAME").append(' ');
}
// Set the app name and the proc id
if (appName != null && pid != null) {
buffer.appendUSASCII(appName).append('[').appendUSASCII(pid).append(']').appendUSASCII(": ");
} else if (appName != null) {
buffer.append(appName).append(": ");
} else if (pid != null) {
buffer.append('[').appendUSASCII(pid).append(']').append(": ");
final String recordProcName = record.getProcessName();
boolean colon = false;
if (appName != null) {
buffer.appendUSASCII(appName);
colon = true;
} else if (recordProcName != null) {
buffer.appendUSASCII(recordProcName);
colon = true;
}
final long recordProcId = record.getProcessId();
if (pid != null) {
buffer.append('[').appendUSASCII(pid).append(']');
colon = true;
} else if (recordProcId != -1) {
buffer.append('[').append(recordProcId).append(']');
colon = true;
}
if (colon) {
buffer.append(':').append(' ');
}
return buffer.toArray();
}
Expand Down

0 comments on commit b3bd0bf

Please sign in to comment.