diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index e164207e2..f2724759f 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -393,7 +393,8 @@ public class Router { buf.append("\n

Most recent console messages:

\n"); for (Iterator iter = msgs.iterator(); iter.hasNext(); ) { String msg = (String)iter.next(); - buf.append("\n"); } buf.append("
").append(msg);
+            buf.append("
");
+            appendLogMessage(buf, msg);
             buf.append("
"); @@ -401,6 +402,82 @@ public class Router { out.write(buf.toString().getBytes()); } + private static int MAX_MSG_LENGTH = 120; + private static final void appendLogMessage(StringBuffer buf, String msg) { + // disable this code for the moment because i think it + // looks ugly (on the router console) + if (true) { + buf.append(msg); + return; + } + if (msg.length() < MAX_MSG_LENGTH) { + buf.append(msg); + return; + } + int newline = msg.indexOf('\n'); + int len = msg.length(); + while ( (msg != null) && (len > 0) ) { + if (newline < 0) { + // last line, trim if necessary + if (len > MAX_MSG_LENGTH) + msg = msg.substring(len-MAX_MSG_LENGTH); + buf.append(msg); + return; + } else if (newline >= MAX_MSG_LENGTH) { + // not the last line, but too long. + // trim the first few chars + String cur = msg.substring(newline-MAX_MSG_LENGTH, newline).trim(); + msg = msg.substring(newline+1); + if (cur.length() > 0) + buf.append(cur).append('\n'); + } else { + // newline <= max_msg_length, so its not the last, + // and not too long + String cur = msg.substring(0, newline).trim(); + msg = msg.substring(newline+1); + if (cur.length() > 0) + buf.append(cur).append('\n'); + } + newline = msg.indexOf('\n'); + len = msg.length(); + } + } + + /** main-ish method for testing appendLogMessage */ + private static final void testAppendLog() { + StringBuffer buf = new StringBuffer(1024); + Router.appendLogMessage(buf, "hi\nhow are you\nh0h0h0"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, "\nfine thanks\nh0h0h0"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, "liar\nblah blah\n"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, "\n"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, ""); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, ".........10........20........30........40........50........6"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, ".........10........\n20........30........40........50........6"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, ".........10........20\n........30........40........50........6"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, ".........10.......\n.20........30........40........50........6"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + Router.appendLogMessage(buf, "\n.........10........20........30........40........50........6"); + System.out.println("line: [" + buf.toString() + "]"); + buf.setLength(0); + } + public void shutdown() { _isAlive = false; I2PThread.removeOOMEventListener(_oomListener);