Skip to content

Commit

Permalink
Add loglevel settings, default rlp_03 logging to info, some minor pro… (
Browse files Browse the repository at this point in the history
#22)

* 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
  • Loading branch information
StrongestNumber9 authored Oct 31, 2024
1 parent 12e02cb commit 5473a0b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
----
Expand Down Expand Up @@ -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
Expand Down
28 changes: 6 additions & 22 deletions src/main/java/com/teragrep/rlp_07/Config.java
Original file line number Diff line number Diff line change
@@ -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"));
Expand All @@ -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");
}
}
29 changes: 17 additions & 12 deletions src/main/java/com/teragrep/rlp_07/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Root level="INFO" additivity="false">
<AppenderRef ref="Console" />
</Root>
<Logger name="com.teragrep.rlp_03" level="TRACE" additivity="false">
<Logger name="com.teragrep.rlp_03" level="INFO" additivity="false">
<AppenderRef ref="Console" />
</Logger>
</Loggers>
Expand Down

0 comments on commit 5473a0b

Please sign in to comment.