From: David ‘Bombe’ Roden Date: Mon, 27 Apr 2015 16:26:19 +0000 (+0200) Subject: Print escape characters to logger X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=82bcd4ba9cb14e6592fb3c4d3c8081319f4da564;p=xudocci.git Print escape characters to logger --- diff --git a/src/main/java/net/pterodactylus/irc/DefaultConnection.java b/src/main/java/net/pterodactylus/irc/DefaultConnection.java index 876aefb..194caf7 100644 --- a/src/main/java/net/pterodactylus/irc/DefaultConnection.java +++ b/src/main/java/net/pterodactylus/irc/DefaultConnection.java @@ -500,11 +500,23 @@ public class DefaultConnection extends AbstractExecutionThreadService implements commandBuilder.append(parameter); } - logger.trace(String.format(">> %s", commandBuilder)); + logger.trace(String.format(">> %s", addEscapeCharacters(commandBuilder))); outputStream.write((commandBuilder.toString() + "\r\n").getBytes("UTF-8")); outputStream.flush(); } + private String addEscapeCharacters(StringBuilder commandBuilder) { + StringBuilder escaped = new StringBuilder(); + for (char c : commandBuilder.toString().toCharArray()) { + if (c < 32) { + escaped.append("\\CTRL[").append((int) c).append("]"); + } else { + escaped.append(c); + } + } + return escaped.toString(); + } + /** * Reads a line of reply from the connection. *