java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.LogsHelper
Helper for the logs page.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringVersion of the JSTL library in use.private final StringBuilderBuffer accumulating a log message.private static final PatternMatches an opening anchor tag.private static final PatternMatches a closing anchor tag.private static final PatternMatches an escaped closing anchor tag.private static final PatternAnchor-stripping runs on every rendered line, so its patterns are hoisted.private static final PatternMatches the doubled brackets around a status icon.private static final StringBundle holding the core translated strings.private static final PatternMatches a connection log line.private static final PatternMatches the date field of a log line.private static final PatternMatches a directory monitor log line.private static final PatternMatches an update manager log line.private static final PatternMatches the log level of a console line.private static final PatternMatches a job queue log line.private static final PatternMatches a read error log line.private static final PatternMatches a restart log line.private static final intLog lines shown on the wrapper log page.private static final String[][]Ordered literal rewrites applied to an escaped log message, up to the double-bracket cleanup.private static final String[][]The middle of the rewrite chain, run after the double-bracket cleanup and before the newline-bullet rewrite.private static final String[][]The tail of the rewrite chain, run after the bullet rewrite.private static final PatternSplits a log entry into its lines.private static final PatternMatches a wrapped log line continuation.private static final StringThe platform line separator.private static final StringConfig key of the last wrapper entry shown.private static final PatternSplits a log entry on spaces.private static final String[][]Ordered literal rewrites applied to a raw wrapper log buffer.Fields inherited from class HelperBase
_context, _log, _out, CHECKED, PROP_ADVANCED, SELECTEDModifier and TypeFieldDescriptionprotected RouterContextThe router context.protected LogThe log instance.protected WriterThe writer for output.static final StringChecked attribute for HTML checkboxes.static final StringProperty key for advanced mode.static final StringSelected attribute for HTML select options.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate StringTranslate a string from the core bundle.(package private) static StringapplyRewrites(String msg, String[][] rewrites) Apply an ordered table of literal rewrites.voidclearThrough(int n, int crit, long wn, long wts, String wf, HttpSession session, String consoleNonce) Clear log messages up through the specified message IDs.private static intcompareLogLines(String a, String b) Compare two log lines by timestamp (first space-delimited token) then content.private StringformatMessages(List<String> msgs) Formats in forward order.Return the Built-By attribute from thei2p.jarmanifest.intReturns the number of critical/error log messages currently displayed.Return HTML rendering of the most recent critical log messages.Return the Jetty version the console is running under.Return the JSTL taglib version string.intCall before getLogs(), getCriticalLogs(), orgetLastMessageNumber()Side effect - calls logManager.flush().intReturns the ID of the most recent log message, forclearThrough(int, int, long, long, String, HttpSession, String).getLogs()Return HTML rendering of the most recent log messages.Return the build revision and date from therouterconsole.warmanifest.Object[]getServiceLogs(StringBuilder obuf) Return HTML rendering of the tail of the wrapper (service) log, with the modification time, last line number and filename of the log file.Return a table row for each signature type this router cannot use.booleanReports whether advanced mode is enabled for this console.private static StringLook up the JSTL version via reflection.private static longreadTextFile(File f, boolean utf8, int maxNumLines, long skipLines, StringBuilder buf) Read in the last few lines of a (newline delimited) textfile, or null if the file doesn't exist.voidsetContext(RouterContext context) Sets the router context whose log manager this helper reads from.Methods inherited from class HelperBase
_t, _t, _t, _x, getChecked, ngettext, setContextId, storeWriterModifier and TypeMethodDescriptionTranslate a string.Translate a string with a parameter.Translate a string with two parameters.static StringMark a string for extraction by xgettext and translation.protected StringgetChecked(String prop) Get the checked attribute for a boolean property.Translate a string with plural forms (ngettext).voidsetContextId(String contextId) Configure this bean to query a particular router context.voidstoreWriter(Writer out) Store the writer for output.
Field Details
LOG_LEVEL_PATTERN
Matches the log level of a console line.BRACKET_CLEANUP_PATTERN
Matches the doubled brackets around a status icon.NEWLINE_STAR_PATTERN
Matches a wrapped log line continuation.NEWLINE_SPLIT
Splits a log entry into its lines.SPACE_SPLIT
Splits a log entry on spaces.LOG_HUTD
Matches an update manager log line.LOG_DATE
Matches the date field of a log line.LOG_CONNECTION
Matches a connection log line.LOG_RESTART
Matches a restart log line.LOG_READ
Matches a read error log line.LOG_DIRMON
Matches a directory monitor log line.LOG_QUEUE
Matches a job queue log line.ANCHOR_ESCAPED
Anchor-stripping runs on every rendered line, so its patterns are hoisted.ANCHOR_CLOSE_ESCAPED
Matches an escaped closing anchor tag.ANCHOR
Matches an opening anchor tag.ANCHOR_CLOSE
Matches a closing anchor tag.MSG_REWRITES_A
Ordered literal rewrites applied to an escaped log message, up to the double-bracket cleanup. Order is load-bearing and not mergeable: this table turns "…" into "...", which MSG_REWRITES_C turns into "…", and it ticks "false" before a later rewrite can restore "[✘] positives" to "false positives".MSG_REWRITES_B
The middle of the rewrite chain, run after the double-bracket cleanup and before the newline-bullet rewrite. The un-ticking has to see the "✔" and "✘" that the first table produces. The last entry converts the inline" * "value separator that source log messages write for the file log into the bullet separator the console renders. The literal•is used rather than•so the rewrite cannot be broken by the HTML escaping that runs before this chain.MSG_REWRITES_C
The tail of the rewrite chain, run after the bullet rewrite. "..." has to be rewritten here, not in the first table, because it is what that table's "…" rewrite produces.WRAPPER_LOG_REWRITES
Ordered literal rewrites applied to a raw wrapper log buffer. Order is load-bearing: "INFO | ERROR" is rewritten into "| ERROR |" first, and the later "| ERROR |" → "| ERR |" then has to see that result._jstlVersion
Version of the JSTL library in use.MAX_WRAPPER_LINES
private static final int MAX_WRAPPER_LINESLog lines shown on the wrapper log page.- See Also:
PROP_LAST_WRAPPER
Config key of the last wrapper entry shown.- See Also:
_msgBuf
Buffer accumulating a log message.NL
The platform line separator.CORE_BUNDLE_NAME
Bundle holding the core translated strings.- See Also:
Constructor Details
LogsHelper
public LogsHelper()Constructor, used by the console when it builds this bean. The rewrite tables below are static, so a bare instance needs no initialization.
Method Details
setContext
Sets the router context whose log manager this helper reads from.- Parameters:
context- the context injected by the servlet container before any log call
getJettyVersion
Return the Jetty version the console is running under.- Returns:
- the Jetty version string, or "n/a" if it cannot be determined
getJstlVersion
Return the JSTL taglib version string.- Returns:
- non-null, "n/a" on failure
jstlVersion
Look up the JSTL version via reflection.- Returns:
- non-null, "n/a" on failure
getLogs
Return HTML rendering of the most recent log messages. Does not call logManager.flush(); callgetCriticalLogs()first to flush.- Returns:
- the formatted log messages, wrapped in a link to the log file
getCriticalLogs
Return HTML rendering of the most recent critical log messages.- Returns:
- the critical logs
getCriticalLogCount
public int getCriticalLogCount()Returns the number of critical/error log messages currently displayed.- Returns:
- the count of critical/error messages
getLastMessageNumber
public int getLastMessageNumber()Returns the ID of the most recent log message, forclearThrough(int, int, long, long, String, HttpSession, String). Call beforegetLogs().- Returns:
- -1 if none
getLastCriticalMessageNumber
public int getLastCriticalMessageNumber()Call before getLogs(), getCriticalLogs(), orgetLastMessageNumber()Side effect - calls logManager.flush().- Returns:
- -1 if none
clearThrough
public void clearThrough(int n, int crit, long wn, long wts, String wf, HttpSession session, String consoleNonce) Clear log messages up through the specified message IDs.- Parameters:
n- -1 for nonecrit- -1 for nonewn- last line number of the wrapper log already shown, or -1 for nonewts- timestamp in ms of the wrapper log line already shown, or -1 for nonewf- filename of the wrapper log already shown, or null for nonesession- the console session holding the nonce, or null to fall back to the process-wide nonceconsoleNonce- the submitted anti-CSRF token, which must equal the session's nonce, or the process-wide one if no session was given
getServiceLogs
Return HTML rendering of the tail of the wrapper (service) log, with the modification time, last line number and filename of the log file.- Parameters:
obuf- out parameter receiving the HTML location and content block- Returns:
- Long timestamp, Long last line number, String filename (escaped)
getBuiltBy
Return the Built-By attribute from thei2p.jarmanifest.- Returns:
- the built by
getRevision
Return the build revision and date from therouterconsole.warmanifest.- Returns:
- the Base-Revision attribute, linked to the commit when built by z3d, or an empty string when the manifest carries no usable attributes
applyRewrites
Apply an ordered table of literal rewrites.Equivalent to chaining
String.replace(CharSequence, CharSequence)down the table in order, so a rewrite routinely matches text an earlier one produced. A rewrite whose needle is absent costs one indexOf and allocates nothing, which is the common case.- Parameters:
msg- the text to rewrite, never nullrewrites- {needle, replacement} pairs, applied in array order- Returns:
- the rewritten text
formatMessages
readTextFile
private static long readTextFile(File f, boolean utf8, int maxNumLines, long skipLines, StringBuilder buf) Read in the last few lines of a (newline delimited) textfile, or null if the file doesn't exist.Same as FileUtil.readTextFile but uses platform encoding, not UTF-8, since the wrapper log cannot be configured: http://stackoverflow.com/questions/14887690/how-do-i-get-the-tanuki-wrapper-log-files-to-be-utf-8-encoded
Warning - this inefficiently allocates a StringBuilder of size maxNumLines*80, so don't make it too big. Warning - converts \r\n to \n.
- Parameters:
f- the file to read, -1 is returned if it does not existutf8- true for utf-8, false for system localemaxNumLines- max number of lines (greater than zero)skipLines- number of lines to skip, or zerobuf- out parameter receiving the trailing lines, each terminated by '\n'- Returns:
- -1 on failure, or number of lines in the file. Does not throw IOException.
_c
isAdvanced
public boolean isAdvanced()Reports whether advanced mode is enabled for this console.- Overrides:
isAdvancedin classHelperBase- Returns:
- true if the advanced-mode property is set, false otherwise
compareLogLines