diff --git a/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/Logger.java b/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/Logger.java index 22490ef356c..b7ec3f9d075 100644 --- a/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/Logger.java +++ b/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/Logger.java @@ -41,13 +41,14 @@ public final class Logger { static { String logFile = null; - File logDirWindows = new File("C:\\wblogs"); //$NON-NLS-1$ - File logDirUNIX = new File("/tmp/wblogs"); //$NON-NLS-1$ + //TODO I think this should go into the workspace metadata instead. + File logDirWindows = new File("C:\\eclipselogs"); //$NON-NLS-1$ + File logDirUNIX = new File("/tmp/eclipselogs"); //$NON-NLS-1$ if (logDirWindows.isDirectory()) { - logFile = logDirWindows + "\\wbterminal.log"; //$NON-NLS-1$ + logFile = logDirWindows + "\\tmterminal.log"; //$NON-NLS-1$ } else if (logDirUNIX.isDirectory()) { - logFile = logDirUNIX + "/wbterminal.log"; //$NON-NLS-1$ + logFile = logDirUNIX + "/tmterminal.log"; //$NON-NLS-1$ } if (logFile != null) { @@ -61,6 +62,71 @@ public final class Logger { } } } + + /** + * Encodes a String such that non-printable control characters are + * converted into user-readable escape sequences for logging. + * @param message String to encode + * @return encoded String + */ + public static final String encode(String message) { + boolean encoded = false; + StringBuffer buf = new StringBuffer(message.length()+32); + for (int i=0; i=' ' && c<'\u007f') { + buf.append(c); + } else { + buf.append('\\'); buf.append('u'); + if (c<='\u0fff') { + buf.append('0'); + if (c<='\u00ff') { + buf.append('0'); + } + } + buf.append(Integer.toHexString(c)); + encoded=true; + } + } + } + if (encoded) { + return buf.toString(); + } + return message; + } + + /** + * Checks if logging is enabled. + * @return true if logging is enabled. + */ + public static final boolean isLogEnabled() { + return (logStream!=null); + } /** * Logs the specified message. Do not append a newline to parameter diff --git a/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/control/TerminalText.java b/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/control/TerminalText.java index f3605985025..ef01b36b126 100644 --- a/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/control/TerminalText.java +++ b/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/control/TerminalText.java @@ -371,7 +371,9 @@ public class TerminalText implements Runnable, ControlListener { * host. */ public synchronized void setNewText(StringBuffer newBuffer) { - Logger.log("new text: '" + newBuffer + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + if (Logger.isLogEnabled()) { + Logger.log("new text: '" + Logger.encode(newBuffer.toString()) + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + } newText = newBuffer; // When continuous output is being processed by the Terminal view code, it diff --git a/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/telnet/TelnetConnection.java b/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/telnet/TelnetConnection.java index b9b019d7065..852f9c4a160 100644 --- a/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/telnet/TelnetConnection.java +++ b/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/telnet/TelnetConnection.java @@ -312,7 +312,7 @@ public class TelnetConnection extends Thread implements TelnetCodes { break; } else { Logger.log("Received " + nRawBytes + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$ - new String(rawBytes, 0, nRawBytes) + "'"); //$NON-NLS-1$ + Logger.encode(new String(rawBytes, 0, nRawBytes)) + "'"); //$NON-NLS-1$ // Process any TELNET protocol data that we receive. Don't // send any TELNET protocol data until we are sure the remote