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 _("File 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 _("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 msgs) { if (msgs.isEmpty()) return "

" + _("No log messages") + "

"; boolean colorize = Boolean.valueOf(_context.getProperty("routerconsole.logs.color")).booleanValue(); StringBuilder buf = new StringBuilder(16*1024); buf.append("\n"); return buf.toString(); } }