Print escape characters to logger
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 Apr 2015 16:26:19 +0000 (18:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 Apr 2015 16:26:19 +0000 (18:26 +0200)
src/main/java/net/pterodactylus/irc/DefaultConnection.java

index 876aefb..194caf7 100644 (file)
@@ -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.
                 *