aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2024-08-03 20:52:00 -0600
committerIván Ávalos <avalos@disroot.org>2024-08-03 20:52:00 -0600
commit55f6d92c09a5b1d8566b53633d07be3d31010d3b (patch)
treeb86bed801b0bbadb72c7e839296dae1d28b12bbb /src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
parentc04ad7d48331253c095fc123ded1b00f6ff871d3 (diff)
parent2788174193def918a3a1a5be3bbed24c9613323f (diff)
downloadtrackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.gz
trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.bz2
trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.zip
Merge tag 'tags/v6.3'
Diffstat (limited to 'src/main/java/org/traccar/handler/network/StandardLoggingHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/network/StandardLoggingHandler.java24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java b/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
index dae93655d..8e63cae4d 100644
--- a/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
+++ b/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java
@@ -24,22 +24,33 @@ import jakarta.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.NetworkMessage;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
+import org.traccar.helper.BufferUtil;
import org.traccar.helper.NetworkUtil;
import org.traccar.model.LogRecord;
import org.traccar.session.ConnectionManager;
+import java.nio.charset.StandardCharsets;
+
public class StandardLoggingHandler extends ChannelDuplexHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(StandardLoggingHandler.class);
private final String protocol;
private ConnectionManager connectionManager;
+ private boolean decodeTextData;
public StandardLoggingHandler(String protocol) {
this.protocol = protocol;
}
@Inject
+ public void setConfig(Config config) {
+ decodeTextData = config.getBoolean(Keys.LOGGER_TEXT_PROTOCOL);
+ }
+
+ @Inject
public void setConnectionManager(ConnectionManager connectionManager) {
this.connectionManager = connectionManager;
}
@@ -61,12 +72,17 @@ public class StandardLoggingHandler extends ChannelDuplexHandler {
}
private LogRecord createLogRecord(ChannelHandlerContext ctx, Object msg) {
- if (msg instanceof NetworkMessage) {
- NetworkMessage networkMessage = (NetworkMessage) msg;
- if (networkMessage.getMessage() instanceof ByteBuf) {
+ if (msg instanceof NetworkMessage networkMessage) {
+ if (networkMessage.getMessage() instanceof ByteBuf data) {
LogRecord record = new LogRecord(ctx.channel().localAddress(), networkMessage.getRemoteAddress());
record.setProtocol(protocol);
- record.setData(ByteBufUtil.hexDump((ByteBuf) networkMessage.getMessage()));
+ if (decodeTextData && BufferUtil.isPrintable(data, data.readableBytes())) {
+ record.setData(data.getCharSequence(
+ data.readerIndex(), data.readableBytes(), StandardCharsets.US_ASCII).toString()
+ .replace("\r", "\\r").replace("\n", "\\n"));
+ } else {
+ record.setData(ByteBufUtil.hexDump(data));
+ }
return record;
}
}