Console: Add log clear buttons (ticket #2449)

This commit is contained in:
zzz
2020-05-04 16:59:46 +00:00
parent ea8e340895
commit f1307614c6
4 changed files with 88 additions and 9 deletions

View File

@ -13,10 +13,12 @@ import java.util.jar.Attributes;
import net.i2p.I2PAppContext;
import net.i2p.crypto.SigType;
import net.i2p.router.web.ConfigServiceHandler;
import net.i2p.router.web.CSSHelper;
import net.i2p.router.web.HelperBase;
import net.i2p.router.web.RouterConsoleRunner;
import net.i2p.util.FileUtil;
import net.i2p.util.Translate;
import net.i2p.util.UIMessages;
public class LogsHelper extends HelperBase {
@ -74,13 +76,55 @@ public class LogsHelper extends HelperBase {
}
/**
* Side effect - calls logManager.flush()
*
*/
public String getCriticalLogs() {
_context.logManager().flush();
return formatMessages(_context.logManager().getBuffer().getMostRecentCriticalMessages());
}
/**
* Call before getLogs()
*
* @return -1 if none
* @since 0.9.46
*/
public int getLastMessageNumber() {
UIMessages msgs = _context.logManager().getBuffer().getUIMessages();
if (msgs.isEmpty())
return -1;
return msgs.getLastMessageID();
}
/**
* Call before getLogs(), getCriticalLogs(), or getLastMessageNumber()
* Side effect - calls logManager.flush()
*
* @return -1 if none
* @since 0.9.46
*/
public int getLastCriticalMessageNumber() {
_context.logManager().flush();
UIMessages msgs = _context.logManager().getBuffer().getCriticalUIMessages();
if (msgs.isEmpty())
return -1;
return msgs.getLastMessageID();
}
/**
* @param n -1 for none
* @param crit -1 for none
* @param consoleNonce must match
* @since 0.9.46
*/
public void clearThrough(int n, int crit, String consoleNonce) {
if (!CSSHelper.getNonce().equals(consoleNonce))
return;
if (n >= 0)
_context.logManager().getBuffer().getUIMessages().clearThrough(n);
if (crit >= 0)
_context.logManager().getBuffer().getCriticalUIMessages().clearThrough(crit);
}
public String getServiceLogs() {
File f = ConfigServiceHandler.wrapperLogFile(_context);
String str;

View File

@ -54,14 +54,36 @@
<tr><td><b>Charset:</b></td><td><%=java.nio.charset.Charset.defaultCharset().name()%></td></tr>
<tr><td><b>Built By:</b></td><td><jsp:getProperty name="logsHelper" property="builtBy" /></tbody></table>
<h3 class="tabletitle"><%=intl._t("Critical Logs")%></h3>
<h3 class="tabletitle"><%=intl._t("Critical Logs")%><%
String consoleNonce = net.i2p.router.web.CSSHelper.getNonce();
String ct1 = request.getParameter("clear");
String ct2 = request.getParameter("crit");
String ctn = request.getParameter("consoleNonce");
if ((ct1 != null || ct2 != null) && ctn != null) {
int ict1 = -1, ict2 = -1;
try { ict1 = Integer.parseInt(ct1); } catch (NumberFormatException nfe) {}
try { ict2 = Integer.parseInt(ct2); } catch (NumberFormatException nfe) {}
logsHelper.clearThrough(ict1, ict2, ctn);
}
int last = logsHelper.getLastCriticalMessageNumber();
if (last >= 0) {
%>&nbsp;<a class="delete" title="<%=intl._t("Clear logs")%>" href="logs?crit=<%=last%>&amp;consoleNonce=<%=consoleNonce%>">[<%=intl._t("Clear logs")%>]</a><%
}
%></h3>
<table id="criticallogs" class="logtable"><tbody>
<tr><td>
<jsp:getProperty name="logsHelper" property="criticalLogs" />
</td></tr>
</tbody></table>
<h3 class="tabletitle"><%=intl._t("Router Logs")%>&nbsp;<a title="<%=intl._t("Configure router logging options")%>" href="configlogging">[<%=intl._t("Configure")%>]</a></h3>
<h3 class="tabletitle"><%=intl._t("Router Logs")%><%
// both links float right, so first one goes last
last = logsHelper.getLastMessageNumber();
if (last >= 0) {
%>&nbsp;<a class="delete" title="<%=intl._t("Clear logs")%>" href="logs?clear=<%=last%>&amp;consoleNonce=<%=consoleNonce%>">[<%=intl._t("Clear logs")%>]</a><%
}
%>&nbsp;<a class="configure" title="<%=intl._t("Configure router logging options")%>" href="configlogging">[<%=intl._t("Configure")%>]</a>
</h3>
<table id="routerlogs" class="logtable"><tbody>
<tr><td>
<jsp:getProperty name="logsHelper" property="logs" />

View File

@ -3998,10 +3998,16 @@ h3#servicedebug a, h3#graphinfo a {
font-size: 0;
}
.main#tunnels h3 a[href^="/configtunnels#"]::after, #criticallogs + h3.tabletitle a::after {
.main#tunnels h3 a[href^="/configtunnels#"]::after, a.configure::after {
content: url(/themes/console/images/buttons/configure.png);
float: right;
padding: 0;
padding: 0 0 0 8px;
}
a.delete::after {
content: url(/themes/console/images/buttons/delete.png);
float: right;
padding: 0 0 0 8px;
}
.main#tunnels h3 a[href^="/configtunnels#"]:hover, h3.tabletitle a:hover::after,

View File

@ -1804,14 +1804,21 @@ h3#exploratorytunnels {
font-size: 0;
}
#tunnels h3 a[href^="/configtunnels#"]::after, #criticallogs + h3.tabletitle a::after {
#tunnels h3 a[href^="/configtunnels#"]::after, a.configure::after {
content: url(/themes/console/images/buttons/configure.png);
float: right;
padding: 0;
padding: 0 0 0 8px;
filter: drop-shadow(0 0 1px #999daf);
}
#tunnels h3 a[href^="/configtunnels#"]:hover, #criticallogs + h3.tabletitle a:hover {
a.delete::after {
content: url(/themes/console/images/buttons/delete.png);
float: right;
padding: 0 0 0 8px;
filter: drop-shadow(0 0 1px #999daf);
}
#tunnels h3 a[href^="/configtunnels#"]:hover, a.configure:hover, a.delete:hover {
filter: drop-shadow(0 0 1px #f60);
}