Files
i2p.i2p/apps/routerconsole/java/src/net/i2p/router/web/LogsHelper.java
zzz 24daf00616 * i2prouter:
- Don't cd to script location, no longer required
    * RouterLaunch:
      - If no wrapper, put wrapper.log in system temp dir
        unless specified with -Dwrapper.logfile=/path/to/wrapper.log
        or it already exists in CWD (for backward compatibility)
      - Append rather than replace wrapper.log
      - Pass wrapper log location to router as a property, so that logs.jsp can find it
    * logs.jsp:
      - Get wrapper log location from a property too
    * runplain.sh:
      - Add path substitution to runplain.sh on install
      - Pass I2P base dir to the router as a property
    * wrapper.config:
      - Put wrapper.log in system temp dir for new installs
      - Pass I2P base dir to the router as a property
    * WorkingDir:
      - Don't migrate an existing install by default
      - Never migrate the data (too hard)
2009-06-13 21:04:27 +00:00

82 lines
2.8 KiB
Java

package net.i2p.router.web;
import java.io.File;
import java.util.List;
import net.i2p.util.FileUtil;
public class LogsHelper extends HelperBase {
public LogsHelper() {}
public String getLogs() {
return formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
}
public String getCriticalLogs() {
return formatMessages(_context.logManager().getBuffer().getMostRecentCriticalMessages());
}
public String getServiceLogs() {
// RouterLaunch puts the location here if no wrapper
String path = System.getProperty("wrapper.logfile");
File f;
if (path != null) {
f = new File(path);
} else {
// look in new and old places
f = new File(System.getProperty("java.io.tmpdir"), "wrapper.log");
if (!f.exists())
f = new File(_context.getBaseDir(), "wrapper.log");
}
String str = FileUtil.readTextFile(f.getAbsolutePath(), 250, false);
if (str == null)
return "";
else {
str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
return "Location: " + f.getAbsolutePath() + "<pre>" + str + "</pre>";
}
}
/***** unused
public String getConnectionLogs() {
return formatMessages(_context.commSystem().getMostRecentErrorMessages());
}
******/
private String formatMessages(List msgs) {
boolean colorize = Boolean.valueOf(_context.getProperty("routerconsole.logs.color")).booleanValue();
StringBuffer buf = new StringBuffer(16*1024);
buf.append("<ul>");
buf.append("<code>\n");
for (int i = msgs.size(); i > 0; i--) {
String msg = (String)msgs.get(i - 1);
buf.append("<li>");
if (colorize) {
String color;
// Homeland Security Advisory System
// http://www.dhs.gov/xinfoshare/programs/Copy_of_press_release_0046.shtm
// but pink instead of yellow for WARN
if (msg.contains("CRIT"))
color = "#cc0000";
else if (msg.contains("ERROR"))
color = "#ff3300";
else if (msg.contains("WARN"))
color = "#ff00cc";
else if (msg.contains("INFO"))
color = "#000099";
else
color = "#006600";
buf.append("<font color=\"").append(color).append("\">");
buf.append(msg.replaceAll("<", "&lt;").replaceAll(">", "&gt;"));
buf.append("</font>");
} else {
buf.append(msg);
}
buf.append("</li>\n");
}
buf.append("</code></ul>\n");
return buf.toString();
}
}