diff --git a/README.md b/README.md index d05fc82..bbad9a8 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ Basic syslog server written in Java. All received messages are written to *stdout*. -The syslog server is able to listen on UDP and/or TCP and parses syslog messages in either RFC5424 or RFC3164 (BSD) format. The default syslog port (514) requires you to run syslogd as root / administrator. If you do not with to do so, you can choose a port number (with the -p flag) above 1024. +The syslog server is able to listen on UDP and/or TCP and parses syslog messages in either RFC5424 or RFC3164 (BSD) format. The default syslog port (514) requires you to run syslogd as root / administrator. If you do not wish to do so, you can choose a port number (with the -p flag) above 1024. ## Usage Instructions -- Install the syslogd package (*.deb* or *.rpm*) from [downloads](https://bitbucket.org/mnellemann/syslogd/downloads/) or compile from source. +- Install the syslogd package (*.deb* or *.rpm*) from [downloads](https://bitbucket.org/mnellemann/syslogd/downloads/) or build from source. - Run *bin/syslogd*, use the *-h* option for help :) ```` diff --git a/build.gradle b/build.gradle index 1d6d727..82fedbd 100644 --- a/build.gradle +++ b/build.gradle @@ -12,18 +12,17 @@ repositories { } dependencies { - compile 'info.picocli:picocli:4.5.2' - annotationProcessor 'info.picocli:picocli-codegen:4.5.2' - - implementation 'org.slf4j:slf4j-api:1.7.+' - runtimeOnly 'ch.qos.logback:logback-classic:1.+' + annotationProcessor 'info.picocli:picocli-codegen:4.6.0' + implementation 'info.picocli:picocli:4.6.0' + implementation 'org.slf4j:slf4j-api:1.7.30' + runtimeOnly 'org.slf4j:slf4j-simple:1.7.30' testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0') testImplementation("org.slf4j:slf4j-simple:1.7.+") } application { - mainClassName = 'biz.nellemann.syslogd.SyslogServer' + mainClassName = 'biz.nellemann.syslogd.Application' } test { @@ -75,3 +74,6 @@ jar { ) } } + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 diff --git a/gradle.properties b/gradle.properties index 7edf4dd..1df34fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ id = syslogd group = biz.nellemann.syslogd -version = 1.0.5 +version = 1.0.7 diff --git a/src/main/java/biz/nellemann/syslogd/SyslogServer.java b/src/main/java/biz/nellemann/syslogd/Application.java similarity index 92% rename from src/main/java/biz/nellemann/syslogd/SyslogServer.java rename to src/main/java/biz/nellemann/syslogd/Application.java index 30e18c7..bad3e9a 100644 --- a/src/main/java/biz/nellemann/syslogd/SyslogServer.java +++ b/src/main/java/biz/nellemann/syslogd/Application.java @@ -27,9 +27,9 @@ import java.util.concurrent.Callable; mixinStandardHelpOptions = true, description = "Basic syslog server.", versionProvider = biz.nellemann.syslogd.VersionProvider.class) -public class SyslogServer implements Callable, LogListener { +public class Application implements Callable, LogListener { - private final static Logger log = LoggerFactory.getLogger(SyslogServer.class); + private final static Logger log = LoggerFactory.getLogger(Application.class); @CommandLine.Option(names = {"-p", "--port"}, description = "Listening port [default: 514].") private int port = 514; @@ -48,7 +48,7 @@ public class SyslogServer implements Callable, LogListener { public static void main(String... args) { - int exitCode = new CommandLine(new SyslogServer()).execute(args); + int exitCode = new CommandLine(new Application()).execute(args); System.exit(exitCode); } diff --git a/src/main/java/biz/nellemann/syslogd/TcpServer.java b/src/main/java/biz/nellemann/syslogd/TcpServer.java index b31ec6c..65f5cf0 100644 --- a/src/main/java/biz/nellemann/syslogd/TcpServer.java +++ b/src/main/java/biz/nellemann/syslogd/TcpServer.java @@ -21,7 +21,6 @@ import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; public class TcpServer { @@ -100,9 +99,8 @@ public class TcpServer { private synchronized void sendEvent(String message) { LogEvent event = new LogEvent( this, message ); - Iterator listeners = eventListeners.iterator(); - while( listeners.hasNext() ) { - listeners.next().onLogEvent( event ); + for (LogListener eventListener : eventListeners) { + eventListener.onLogEvent(event); } } diff --git a/src/main/java/biz/nellemann/syslogd/UdpServer.java b/src/main/java/biz/nellemann/syslogd/UdpServer.java index b2b1d67..8e34d71 100644 --- a/src/main/java/biz/nellemann/syslogd/UdpServer.java +++ b/src/main/java/biz/nellemann/syslogd/UdpServer.java @@ -20,7 +20,6 @@ import java.net.DatagramPacket; import java.net.DatagramSocket; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; public class UdpServer extends Thread { @@ -57,9 +56,8 @@ public class UdpServer extends Thread { private synchronized void sendEvent(String message) { LogEvent event = new LogEvent( this, message); - Iterator listeners = eventListeners.iterator(); - while( listeners.hasNext() ) { - listeners.next().onLogEvent( event ); + for (LogListener eventListener : eventListeners) { + eventListener.onLogEvent(event); } } diff --git a/src/main/resources/simplelogger.properties b/src/main/resources/simplelogger.properties new file mode 100644 index 0000000..bd2eeaa --- /dev/null +++ b/src/main/resources/simplelogger.properties @@ -0,0 +1,4 @@ +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.showShortLogName=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS +org.slf4j.simpleLogger.levelInBrackets=true diff --git a/src/test/groovy/biz/nellemann/syslogd/SyslogParserTest.groovy b/src/test/groovy/biz/nellemann/syslogd/SyslogParserTest.groovy index d738076..d1d2a0c 100644 --- a/src/test/groovy/biz/nellemann/syslogd/SyslogParserTest.groovy +++ b/src/test/groovy/biz/nellemann/syslogd/SyslogParserTest.groovy @@ -32,6 +32,20 @@ class SyslogParserTest extends Specification { msg.application == "padmin" } + void "test another rfc3164 aix/vios message"() { + + setup: + def input = "<13>Dec 18 10:09:22 Message forwarded from p924vio1: root: [errnotify] seq: 24266 - AA8AB241 1218100920 T O OPERATOR OPERATOR NOTIFICATION" + + when: + SyslogMessage msg = SyslogParser.parseRfc3164(input) + + then: + msg.message == "[errnotify] seq: 24266 - AA8AB241 1218100920 T O OPERATOR OPERATOR NOTIFICATION" + msg.hostname == "p924vio1" + msg.application == "root" + } + void "test rfc3164 normal message"() { setup: