Author: nextgens
Date: 2007-11-27 16:01:47 +0000 (Tue, 27 Nov 2007)
New Revision: 15965
Modified:
trunk/freenet/src/freenet/clients/http/StartupToadletServer.java
trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
Log:
Factorize the code displaying wrapper.log. Display the logfile when we are the
node is shutting down
Modified: trunk/freenet/src/freenet/clients/http/StartupToadletServer.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StartupToadletServer.java
2007-11-27 14:18:20 UTC (rev 15964)
+++ trunk/freenet/src/freenet/clients/http/StartupToadletServer.java
2007-11-27 16:01:47 UTC (rev 15965)
@@ -92,17 +92,7 @@
HTMLNode infoboxContent =
ctx.getPageMaker().getContentNode(infobox);
infoboxContent.addChild("#", "Your freenet node is starting up,
please hold on.");
- final File logs = new File("wrapper.log");
- long logSize = logs.length();
- if(logs.exists() && logs.isFile() && logs.canRead() && logSize
> 0) {
- HTMLNode logInfobox =
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-info", "Current
status"));
- HTMLNode logInfoboxContent =
ctx.getPageMaker().getContentNode(logInfobox);
- boolean isShortFile = logSize < 2000;
- String content = FileUtil.readUTF(logs, (isShortFile ? 0 :
logSize - 2000));
- int eol = content.indexOf('\n');
- boolean shallStripFirstLine = (!isShortFile) && (eol > 0);
- logInfoboxContent.addChild("%",
content.substring((shallStripFirstLine ? eol+1 : 0)).replaceAll("\n",
"<br>\n"));
- }
+ WelcomeToadlet.maybeDisplayWrapperLogfile(ctx, contentNode);
//TODO: send a Retry-After header ?
writeHTMLReply(ctx, 503, desc, pageNode.generate());
}
Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2007-11-27
14:18:20 UTC (rev 15964)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2007-11-27
16:01:47 UTC (rev 15965)
@@ -436,6 +436,9 @@
HTMLNode infobox =
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-information",
l10n("shutdownDone")));
HTMLNode infoboxContent =
ctx.getPageMaker().getContentNode(infobox);
infoboxContent.addChild("#", l10n("thanks"));
+
+ WelcomeToadlet.maybeDisplayWrapperLogfile(ctx, contentNode);
+
this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
return;
} else if (request.isParameterSet("restarted")) {
@@ -611,4 +614,20 @@
private String l10n(String key, String pattern, String value) {
return L10n.getString("WelcomeToadlet." + key, new String[]{pattern},
new String[]{value});
}
+
+ public static void maybeDisplayWrapperLogfile(ToadletContext ctx, HTMLNode
contentNode) {
+ final File logs = new File("wrapper.log");
+ long logSize = logs.length();
+ if(logs.exists() && logs.isFile() && logs.canRead() && logSize > 0) {
+ try {
+ HTMLNode logInfobox =
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-info", "Current
status"));
+ HTMLNode logInfoboxContent =
ctx.getPageMaker().getContentNode(logInfobox);
+ boolean isShortFile = logSize < 2000;
+ String content = FileUtil.readUTF(logs, (isShortFile ? 0 :
logSize - 2000));
+ int eol = content.indexOf('\n');
+ boolean shallStripFirstLine = (!isShortFile) && (eol > 0);
+ logInfoboxContent.addChild("%",
content.substring((shallStripFirstLine ? eol + 1 : 0)).replaceAll("\n",
"<br>\n"));
+ } catch(IOException e) {}
+ }
+ }
}