From 9f2e804e9b36caf9a337ed7976f4abe48c7d934a Mon Sep 17 00:00:00 2001 From: Negar Safinianaini Date: Wed, 4 May 2016 11:28:44 +0200 Subject: [PATCH] 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. --- src/main/java/org/graylog2/syslog4j/SyslogIF.java | 2 ++ .../org/graylog2/syslog4j/impl/AbstractSyslog.java | 14 ++++++++++++++ .../syslog4j/impl/multiple/MultipleSyslog.java | 4 ++++ .../syslog4j/impl/net/tcp/TCPNetSyslogConfig.java | 10 +++++----- .../impl/net/tcp/TCPNetSyslogConfigIF.java | 4 ++-- .../syslog4j/impl/net/tcp/TCPNetSyslogWriter.java | 4 ++-- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/graylog2/syslog4j/SyslogIF.java b/src/main/java/org/graylog2/syslog4j/SyslogIF.java index 83f5d55..92d90e4 100644 --- a/src/main/java/org/graylog2/syslog4j/SyslogIF.java +++ b/src/main/java/org/graylog2/syslog4j/SyslogIF.java @@ -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); diff --git a/src/main/java/org/graylog2/syslog4j/impl/AbstractSyslog.java b/src/main/java/org/graylog2/syslog4j/impl/AbstractSyslog.java index b7bdc37..f1f325a 100644 --- a/src/main/java/org/graylog2/syslog4j/impl/AbstractSyslog.java +++ b/src/main/java/org/graylog2/syslog4j/impl/AbstractSyslog.java @@ -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); diff --git a/src/main/java/org/graylog2/syslog4j/impl/multiple/MultipleSyslog.java b/src/main/java/org/graylog2/syslog4j/impl/multiple/MultipleSyslog.java index 6cfad8f..7459c14 100644 --- a/src/main/java/org/graylog2/syslog4j/impl/multiple/MultipleSyslog.java +++ b/src/main/java/org/graylog2/syslog4j/impl/multiple/MultipleSyslog.java @@ -178,4 +178,8 @@ public class MultipleSyslog implements SyslogIF { } + public void log(int level, SyslogMessageIF message, Date datetime) { + + } + } diff --git a/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfig.java b/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfig.java index 5a63cb6..df881c9 100644 --- a/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfig.java +++ b/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfig.java @@ -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() { diff --git a/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfigIF.java b/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfigIF.java index 5e5ea65..5e760ab 100644 --- a/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfigIF.java +++ b/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogConfigIF.java @@ -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(); } diff --git a/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogWriter.java b/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogWriter.java index 0401e7c..3e4a535 100644 --- a/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogWriter.java +++ b/src/main/java/org/graylog2/syslog4j/impl/net/tcp/TCPNetSyslogWriter.java @@ -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);