package net.i2p.router.web;
import java.util.Iterator;
import java.util.Properties;
import java.util.TreeSet;
import net.i2p.router.RouterContext;
public class ConfigLoggingHelper {
private RouterContext _context;
/**
* Configure this bean to query a particular router context
*
* @param contextId begging few characters of the routerHash, or null to pick
* the first one we come across.
*/
public void setContextId(String contextId) {
try {
_context = ContextHelper.getContext(contextId);
} catch (Throwable t) {
t.printStackTrace();
}
}
public ConfigLoggingHelper() {}
public String getLogFilePattern() {
return _context.logManager().getBaseLogfilename();
}
public String getRecordPattern() {
return new String(_context.logManager().getFormat());
}
public String getDatePattern() {
return _context.logManager().getDateFormatPattern();
}
public String getMaxFileSize() {
int bytes = _context.logManager().getFileSize();
if (bytes == 0) return "1m";
if (bytes > 1024*1024*1024)
return (bytes/(1024*1024*1024)) + "g";
else if (bytes > 1024*1024)
return (bytes/(1024*1024)) + "m";
else
return (bytes/(1024)) + "k";
}
public String getLogLevelTable() {
StringBuffer buf = new StringBuffer(32*1024);
Properties limits = _context.logManager().getLimits();
TreeSet sortedLogs = new TreeSet();
for (Iterator iter = limits.keySet().iterator(); iter.hasNext(); ) {
String prefix = (String)iter.next();
sortedLogs.add(prefix);
}
buf.append("
\n");
buf.append("Add additional logging statements above. Example: net.i2p.router.tunnel=WARN
");
buf.append("Or put entries in the logger.config file. Example: logger.record.net.i2p.router.tunnel=WARN
");
buf.append("Valid levels are DEBUG, INFO, WARN, ERROR, CRIT\n");
return buf.toString();
}
public String getDefaultLogLevelBox() {
String cur = _context.logManager().getDefaultLimit();
StringBuffer buf = new StringBuffer(128);
buf.append("\n");
return buf.toString();
}
}