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() { String str = formatMessages(_context.logManager().getBuffer().getMostRecentMessages()); return "Location: " + _context.logManager().currentFile() + "

" + str; } 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("<", "<").replaceAll(">", ">"); return "Location: " + f.getAbsolutePath() + "
" + str + "
"; } } /***** unused public String getConnectionLogs() { return formatMessages(_context.commSystem().getMostRecentErrorMessages()); } ******/ private String formatMessages(List msgs) { boolean colorize = Boolean.valueOf(_context.getProperty("routerconsole.logs.color")).booleanValue(); StringBuilder buf = new StringBuilder(16*1024); buf.append("\n"); return buf.toString(); } }