From 5473a0b2f8351d3465f5c4f78a823a1a81e35bb1 Mon Sep 17 00:00:00 2001
From: Strongest Number 9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Thu, 31 Oct 2024 09:03:54 +0200
Subject: [PATCH] =?UTF-8?q?Add=20loglevel=20settings,=20default=20rlp=5F03?=
=?UTF-8?q?=20logging=20to=20info,=20some=20minor=20pro=E2=80=A6=20(#22)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Add loglevel settings, default rlp_03 logging to info, some minor properties cleanup
* Adds note about logging levels
* Clarifies that it is internal components for logging level
---
Dockerfile | 2 +-
README.adoc | 7 +++--
src/main/java/com/teragrep/rlp_07/Config.java | 28 ++++--------------
src/main/java/com/teragrep/rlp_07/Main.java | 29 +++++++++++--------
src/main/resources/log4j2.xml | 2 +-
5 files changed, 29 insertions(+), 39 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index f7a2d8f..4445d74 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,4 +3,4 @@ COPY rpm/target/rpm/com.teragrep-rlp_07/RPMS/noarch/com.teragrep-rlp_07-*.rpm /r
COPY src/main/resources/keystore-server.jks /keystore/keystore-server.jks
RUN dnf -y install /rpm/*.rpm && yum clean all
WORKDIR /opt/teragrep/rlp_07
-ENTRYPOINT /usr/bin/java -Dport="${RLP_07_PORT:-1601}" -Dtls="${RLP_07_TLS:-false}" -DtlsKeystorePassword="${RLP_07_TLS_KEYSTOREPASSWORD:-changeit}" -DtlsKeystore="${RLP_07_TLS_KEYSTORE:-/keystore/keystore-server.jks}" -jar lib/rlp_07.jar
+ENTRYPOINT /usr/bin/java -Dport="${RLP_07_PORT:-1601}" -Dtls="${RLP_07_TLS:-false}" -DtlsKeystorePassword="${RLP_07_TLS_KEYSTOREPASSWORD:-changeit}" -DtlsKeystore="${RLP_07_TLS_KEYSTORE:-/keystore/keystore-server.jks}" -Dloglevel="${RLP_07_LOGLEVEL:-info}" -jar lib/rlp_07.jar
diff --git a/README.adoc b/README.adoc
index cff420d..7f15b9b 100644
--- a/README.adoc
+++ b/README.adoc
@@ -22,9 +22,7 @@ Custom server keystore can be supplied with "-DtlsKeystore=path/to/file.jks".
Custom server keystore password can be supplied with "-DtlsKeystorePassword=MyCustomPassword".
-Debug output
-
-See src/main/resources for the log4j2.xml
+Internal component logging levels can be managed with "-Dloglevel=INFO". You can read more about logging levels https://logging.apache.org/log4j/2.x/manual/customloglevels.html[here].
[source, bash]
----
@@ -54,6 +52,9 @@ The container respects the following environment variables
|RLP_07_TLS_KEYSTOREPASSWORD=changeit
|-DtlsKeystorePassword=changeit
+
+|RLP_07_LOGLEVEL=INFO
+|-Dloglevel=INFO
|===
== Contributing
diff --git a/src/main/java/com/teragrep/rlp_07/Config.java b/src/main/java/com/teragrep/rlp_07/Config.java
index 397b1d6..6a52bff 100644
--- a/src/main/java/com/teragrep/rlp_07/Config.java
+++ b/src/main/java/com/teragrep/rlp_07/Config.java
@@ -1,27 +1,10 @@
package com.teragrep.rlp_07;
public class Config {
- private final int port;
-
- public int getPort() {
- return port;
- }
-
- private final boolean isTls;
-
- public boolean isTls() {
- return isTls;
- }
-
- private final String keystorePassword;
-
- public String getKeystorePassword() {
- return keystorePassword;
- }
-
- private final String keystorePath;
- public String getKeystorePath() {
- return keystorePath;
- }
+ public final int port;
+ public final boolean isTls;
+ public final String keystorePassword;
+ public final String keystorePath;
+ public final String loglevel;
public Config() {
try {
port = Integer.parseInt(System.getProperty("port", "1601"));
@@ -31,5 +14,6 @@ public Config() {
isTls = Boolean.parseBoolean(System.getProperty("tls", "false"));
keystorePassword = System.getProperty("tlsKeystorePassword", "changeit");
keystorePath = System.getProperty("tlsKeystore", null);
+ loglevel = System.getProperty("loglevel");
}
}
diff --git a/src/main/java/com/teragrep/rlp_07/Main.java b/src/main/java/com/teragrep/rlp_07/Main.java
index 9a05607..ce97cf9 100644
--- a/src/main/java/com/teragrep/rlp_07/Main.java
+++ b/src/main/java/com/teragrep/rlp_07/Main.java
@@ -3,6 +3,8 @@
import com.teragrep.rlp_03.FrameProcessor;
import com.teragrep.rlp_03.Server;
import com.teragrep.rlp_03.SyslogFrameProcessor;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,37 +29,40 @@ class Main {
private static final FrameProcessor syslogFrameProcessor = new SyslogFrameProcessor(byteConsumer);
static Config config;
- public static void main(String[] args) throws IOException, InterruptedException {
+ public static void main(String[] args) {
config = new Config();
+ if(config.loglevel != null) {
+ LOGGER.info("Setting loglevel to <[{}]>", config.loglevel);
+ Configurator.setAllLevels("com.teragrep", Level.valueOf(config.loglevel));
+ }
try {
- if (config.isTls()) {
+ if (config.isTls) {
tlsServer();
} else {
plainServer();
}
}
catch (Exception e) {
- LOGGER.error("Failed to run: " + e.getMessage());
+ LOGGER.error("Failed to run: <{}>", e.getMessage(), e);
}
}
private static void plainServer() throws IOException, InterruptedException {
- LOGGER.info("Starting plain server on port " + config.getPort());
- Server relpServer = new Server(config.getPort(), syslogFrameProcessor);
+ LOGGER.info("Starting plain server on port <[{}]>", config.port);
+ Server relpServer = new Server(config.port, syslogFrameProcessor);
relpServer.start();
Thread.sleep(Long.MAX_VALUE);
}
private static void tlsServer() throws IOException, InterruptedException {
- LOGGER.info("Starting TLS server on port " + config.getPort());
+ LOGGER.info("Starting TLS server on port <[{}]>", config.port);
- String keystorePath = config.getKeystorePath();
InputStream keystoreStream;
- if(keystorePath != null) {
+ if(config.keystorePath != null) {
LOGGER.info("Using user supplied keystore");
- Path path = Paths.get(keystorePath);
+ Path path = Paths.get(config.keystorePath);
if(!path.toFile().exists()) {
- throw new RuntimeException("File " + keystorePath + " doesn't exist");
+ throw new RuntimeException("File " + config.keystorePath + " doesn't exist");
}
keystoreStream = Files.newInputStream(path);
}
@@ -71,7 +76,7 @@ private static void tlsServer() throws IOException, InterruptedException {
try {
sslContext = TLSContextFactory.authenticatedContext(
keystoreStream,
- config.getKeystorePassword(),
+ config.keystorePassword,
"TLSv1.3"
);
} catch (GeneralSecurityException e) {
@@ -84,7 +89,7 @@ private static void tlsServer() throws IOException, InterruptedException {
return sslEngine;
};
- Server relpServer = new Server(config.getPort(), syslogFrameProcessor, sslContext, sslEngineFunction);
+ Server relpServer = new Server(config.port, syslogFrameProcessor, sslContext, sslEngineFunction);
relpServer.start();
Thread.sleep(Long.MAX_VALUE);
}
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
index 7b8d350..8292303 100644
--- a/src/main/resources/log4j2.xml
+++ b/src/main/resources/log4j2.xml
@@ -8,7 +8,7 @@
-
+