package net.i2p.router.web;
import java.io.File;
import java.util.List;
import net.i2p.util.FileUtil;
import net.i2p.util.VersionComparator;
import org.mortbay.http.Version;
import org.tanukisoftware.wrapper.WrapperManager;
public class LogsHelper extends HelperBase {
private static final String LOCATION_AVAILABLE = "3.3.7";
/** @since 0.8.12 */
public String getJettyVersion() {
return jettyVersion();
}
/** @since 0.8.13 */
static String jettyVersion() {
try {
String rv = Version.getImplVersion();
if (rv.startsWith("Jetty/"))
rv = rv.substring(6);
return rv;
} catch (Throwable t) {
return "unknown";
}
}
public String getLogs() {
String str = formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
return _("File location") + ": " + _context.logManager().currentFile() + "
" + str;
}
public String getCriticalLogs() {
return formatMessages(_context.logManager().getBuffer().getMostRecentCriticalMessages());
}
public String getServiceLogs() {
File f = null;
if (_context.hasWrapper()) {
String wv = System.getProperty("wrapper.version");
if (wv != null && (new VersionComparator()).compare(wv, LOCATION_AVAILABLE) >= 0) {
try {
f = WrapperManager.getWrapperLogFile();
} catch (Throwable t) {}
}
}
if (f == null || !f.exists()) {
// RouterLaunch puts the location here if no wrapper
String path = System.getProperty("wrapper.logfile");
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 _("File not found") + ": " + f.getAbsolutePath() + "
";
else {
str = str.replace("&", "&").replace("<", "<").replace(">", ">");
return _("File location") + ": " + f.getAbsolutePath() + "
" + str + ""; } } /***** unused public String getConnectionLogs() { return formatMessages(_context.commSystem().getMostRecentErrorMessages()); } ******/ private final static String NL = System.getProperty("line.separator"); /** formats in reverse order */ private String formatMessages(List
" + _("No log messages") + "
"; boolean colorize = _context.getBooleanPropertyDefaultTrue("routerconsole.logs.color"); StringBuilder buf = new StringBuilder(16*1024); buf.append("