Renamed frame header to octet counting as specified in RFC 6587. (#7)

* Renamed frame header to octet counting as specified in RFC 6587.
* Introduced date argument in log method when structured message is sent as argument.
This commit is contained in:
Negar Safinianaini 2016-05-04 11:28:44 +02:00 committed by Jochen Schalanda
parent fdba539aa8
commit 9f2e804e9b
6 changed files with 29 additions and 9 deletions

View File

@ -44,6 +44,8 @@ public interface SyslogIF extends SyslogConstants {
public void emergency(String message);
public void log(int level, SyslogMessageIF message);
public void log(int level, SyslogMessageIF message, Date datetime);
public void debug(SyslogMessageIF message);

View File

@ -149,6 +149,20 @@ public abstract class AbstractSyslog implements SyslogIF {
log(getMessageProcessor(), level, message.createMessage());
}
}
public void log(int level, SyslogMessageIF message, Date datetime) {
if (message instanceof StructuredSyslogMessageIF) {
if (getMessageProcessor() instanceof StructuredSyslogMessageProcessor) {
log(getMessageProcessor(), level, message.createMessage(), datetime);
} else {
log(getStructuredMessageProcessor(), level, message.createMessage(), datetime);
}
} else {
log(getMessageProcessor(), level, message.createMessage(), datetime);
}
}
public void debug(String message) {
log(LEVEL_DEBUG, message);

View File

@ -178,4 +178,8 @@ public class MultipleSyslog implements SyslogIF {
}
public void log(int level, SyslogMessageIF message, Date datetime) {
}
}

View File

@ -54,7 +54,7 @@ public class TCPNetSyslogConfig extends AbstractNetSyslogConfig implements TCPNe
* 89 <165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473]
*
*/
private boolean useFrameHeader;
private boolean useOctetCounting;
public TCPNetSyslogConfig() {
initialize();
@ -161,12 +161,12 @@ public class TCPNetSyslogConfig extends AbstractNetSyslogConfig implements TCPNe
this.freshConnectionInterval = freshConnectionInterval;
}
public void setUseFrameHeader(boolean useFrameHeader) {
this.useFrameHeader = useFrameHeader;
public void setUseOctetCounting(boolean useOctetCounting) {
this.useOctetCounting = useOctetCounting;
}
public boolean isUseFrameHeader() {
return this.useFrameHeader;
public boolean isUseOctetCounting() {
return this.useOctetCounting;
}
public Class getSyslogWriterClass() {

View File

@ -46,7 +46,7 @@ public interface TCPNetSyslogConfigIF extends AbstractNetSyslogConfigIF {
public void setFreshConnectionInterval(int interval);
public void setUseFrameHeader(boolean useFrameHeader);
public void setUseOctetCounting(boolean useFrameHeader);
public boolean isUseFrameHeader();
public boolean isUseOctetCounting();
}

View File

@ -141,7 +141,7 @@ public class TCPNetSyslogWriter extends AbstractSyslogWriter {
OutputStream os = currentSocket.getOutputStream();
String frameHeader = "";
if(this.tcpNetSyslogConfig.isUseFrameHeader()){
if(this.tcpNetSyslogConfig.isUseOctetCounting()){
frameHeader = message.length + " ";
}
@ -152,7 +152,7 @@ public class TCPNetSyslogWriter extends AbstractSyslogWriter {
os.write(frameHeader.getBytes());
os.write(message);
if(!this.tcpNetSyslogConfig.isUseFrameHeader()) {
if(!this.tcpNetSyslogConfig.isUseOctetCounting()) {
byte[] delimiterSequence = this.tcpNetSyslogConfig.getDelimiterSequence();
if (delimiterSequence != null && delimiterSequence.length > 0) {
os.write(delimiterSequence);