1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

bug 209665: Need ability to log byte streams from Terminal for debugging

https://bugs.eclipse.org/bugs/show_bug.cgi?id=209665
This commit is contained in:
Michael Scharf 2007-11-14 06:15:07 +00:00
parent e371fa05ff
commit 9f10faedc8
3 changed files with 53 additions and 5 deletions

View file

@ -311,10 +311,6 @@ public class TelnetConnection extends Thread implements TelnetCodes {
terminalControl.setState(TerminalState.CLOSED); terminalControl.setState(TerminalState.CLOSED);
break; break;
} else { } else {
if(Logger.isLogEnabled())
Logger.log("Received " + nRawBytes + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
Logger.encode(new String(rawBytes, 0, nRawBytes)) + "'"); //$NON-NLS-1$
// Process any TELNET protocol data that we receive. Don't // Process any TELNET protocol data that we receive. Don't
// send any TELNET protocol data until we are sure the remote // send any TELNET protocol data until we are sure the remote
// endpoint is a TELNET server. // endpoint is a TELNET server.

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Michael Scharf (Wind River) - initial API and implementation
*******************************************************************************/
package org.eclipse.tm.internal.terminal.emulator;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
public class LoggingOutputStream extends FilterOutputStream {
public LoggingOutputStream(OutputStream out) {
super(out);
}
public void write(byte[] b, int off, int len) throws IOException {
if(Logger.isLogEnabled())
Logger.log("Received " + len + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
Logger.encode(new String(b, 0, len)) + "'"); //$NON-NLS-1$
// we cannot call super.write, because this would call our write
// which logs character by character.....
//super.write(b, off, len);
if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
throw new IndexOutOfBoundsException();
for (int i = 0 ; i < len ; i++) {
super.write(b[off + i]);
}
}
public void write(int b) throws IOException {
if(Logger.isLogEnabled())
Logger.log("Received " + 1 + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
Logger.encode(new String(new byte[]{(byte)b}, 0, 1)) + "'"); //$NON-NLS-1$
super.write(b);
}
}

View file

@ -581,7 +581,11 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
} }
public OutputStream getRemoteToTerminalOutputStream() { public OutputStream getRemoteToTerminalOutputStream() {
return fInputStream.getOutputStream(); if(Logger.isLogEnabled()) {
return new LoggingOutputStream(fInputStream.getOutputStream());
} else {
return fInputStream.getOutputStream();
}
} }
protected boolean isLogCharEnabled() { protected boolean isLogCharEnabled() {
return TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_CHAR); return TerminalPlugin.isOptionEnabled(Logger.TRACE_DEBUG_LOG_CHAR);