From 70a0832b1d071331cc738eb13bd250d707da1662 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Wed, 3 Jan 2007 11:52:41 +0000 Subject: [PATCH] Improve Terminal Logging by quoting characters. Move logs to "eclipselogs" --- .../org.eclipse.rse.build/maps/terminal.map | 2 +- .../src/org/eclipse/tm/terminal/Logger.java | 74 ++++++++++++++++++- .../internal/control/TerminalText.java | 4 +- .../internal/telnet/TelnetConnection.java | 2 +- 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/releng/org.eclipse.rse.build/maps/terminal.map b/releng/org.eclipse.rse.build/maps/terminal.map index d4b94d0028f..1e6c9131eae 100644 --- a/releng/org.eclipse.rse.build/maps/terminal.map +++ b/releng/org.eclipse.rse.build/maps/terminal.map @@ -3,7 +3,7 @@ feature@org.eclipse.tm.terminal.sdk=v20061220,:pserver:anonymous:none@dev.eclips feature@org.eclipse.tm.terminal.serial=v20061215,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.serial-feature feature@org.eclipse.tm.terminal.ssh=v20061220,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.ssh-feature feature@org.eclipse.tm.terminal.view=v20061220,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view-feature -plugin@org.eclipse.tm.terminal=v20061220,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal +plugin@org.eclipse.tm.terminal=v20070102,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal plugin@org.eclipse.tm.terminal.serial=v20061221,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.serial plugin@org.eclipse.tm.terminal.ssh=v20061215,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.ssh plugin@org.eclipse.tm.terminal.view=v20061220,:pserver:anonymous:none@dev.eclipse.org:/cvsroot/dsdp,,org.eclipse.tm.core/terminal/org.eclipse.tm.terminal.view \ No newline at end of file diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/Logger.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/Logger.java index 22490ef356c..b7ec3f9d075 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/Logger.java +++ b/terminal/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/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/control/TerminalText.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/control/TerminalText.java index f3605985025..ef01b36b126 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/control/TerminalText.java +++ b/terminal/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/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/telnet/TelnetConnection.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/telnet/TelnetConnection.java index b9b019d7065..852f9c4a160 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/terminal/internal/telnet/TelnetConnection.java +++ b/terminal/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