java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.LogsHelper

public class LogsHelperextends HelperBase
Helper for the logs page.
  • Field Details

    • LOG_LEVEL_PATTERN

      private static final Pattern LOG_LEVEL_PATTERN
      Matches the log level of a console line.
    • BRACKET_CLEANUP_PATTERN

      private static final Pattern BRACKET_CLEANUP_PATTERN
      Matches the doubled brackets around a status icon.
    • NEWLINE_STAR_PATTERN

      private static final Pattern NEWLINE_STAR_PATTERN
      Matches a wrapped log line continuation.
    • NEWLINE_SPLIT

      private static final Pattern NEWLINE_SPLIT
      Splits a log entry into its lines.
    • SPACE_SPLIT

      private static final Pattern SPACE_SPLIT
      Splits a log entry on spaces.
    • LOG_HUTD

      private static final Pattern LOG_HUTD
      Matches an update manager log line.
    • LOG_DATE

      private static final Pattern LOG_DATE
      Matches the date field of a log line.
    • LOG_CONNECTION

      private static final Pattern LOG_CONNECTION
      Matches a connection log line.
    • LOG_RESTART

      private static final Pattern LOG_RESTART
      Matches a restart log line.
    • LOG_READ

      private static final Pattern LOG_READ
      Matches a read error log line.
    • LOG_DIRMON

      private static final Pattern LOG_DIRMON
      Matches a directory monitor log line.
    • LOG_QUEUE

      private static final Pattern LOG_QUEUE
      Matches a job queue log line.
    • ANCHOR_ESCAPED

      private static final Pattern ANCHOR_ESCAPED
      Anchor-stripping runs on every rendered line, so its patterns are hoisted.
    • ANCHOR_CLOSE_ESCAPED

      private static final Pattern ANCHOR_CLOSE_ESCAPED
      Matches an escaped closing anchor tag.
    • ANCHOR

      private static final Pattern ANCHOR
      Matches an opening anchor tag.
    • ANCHOR_CLOSE

      private static final Pattern ANCHOR_CLOSE
      Matches a closing anchor tag.
    • MSG_REWRITES_A

      private static final String[][] 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

      private static final String[][] 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

      private static final String[][] 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

      private static final String[][] 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

      private static final String _jstlVersion
      Version of the JSTL library in use.
    • MAX_WRAPPER_LINES

      private static final int MAX_WRAPPER_LINES
      Log lines shown on the wrapper log page.
      See Also:
    • PROP_LAST_WRAPPER

      private static final String PROP_LAST_WRAPPER
      Config key of the last wrapper entry shown.
      See Also:
    • _msgBuf

      private final StringBuilder _msgBuf
      Buffer accumulating a log message.
    • NL

      private static final String NL
      The platform line separator.
    • CORE_BUNDLE_NAME

      private static final String 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

      public void setContext(RouterContext context)
      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

      public String getJettyVersion()
      Return the Jetty version the console is running under.
      Returns:
      the Jetty version string, or "n/a" if it cannot be determined
    • getUnavailableCrypto

      public String getUnavailableCrypto()
      Return a table row for each signature type this router cannot use.
      Returns:
      the table rows listing each unavailable signature type, empty if every type is available
    • getJstlVersion

      public String getJstlVersion()
      Return the JSTL taglib version string.
      Returns:
      non-null, "n/a" on failure
    • jstlVersion

      private static String jstlVersion()
      Look up the JSTL version via reflection.
      Returns:
      non-null, "n/a" on failure
    • getLogs

      public String getLogs()
      Return HTML rendering of the most recent log messages. Does not call logManager.flush(); call getCriticalLogs() first to flush.
      Returns:
      the formatted log messages, wrapped in a link to the log file
    • getCriticalLogs

      public String 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, for clearThrough(int, int, long, long, String, HttpSession, String). Call before getLogs().
      Returns:
      -1 if none
    • getLastCriticalMessageNumber

      public int getLastCriticalMessageNumber()
      Call before getLogs(), getCriticalLogs(), or getLastMessageNumber() 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 none
      crit - -1 for none
      wn - last line number of the wrapper log already shown, or -1 for none
      wts - timestamp in ms of the wrapper log line already shown, or -1 for none
      wf - filename of the wrapper log already shown, or null for none
      session - the console session holding the nonce, or null to fall back to the process-wide nonce
      consoleNonce - the submitted anti-CSRF token, which must equal the session's nonce, or the process-wide one if no session was given
    • getServiceLogs

      public 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.
      Parameters:
      obuf - out parameter receiving the HTML location and content block
      Returns:
      Long timestamp, Long last line number, String filename (escaped)
    • getBuiltBy

      public String getBuiltBy()
      Return the Built-By attribute from the i2p.jar manifest.
      Returns:
      the built by
    • getRevision

      public String getRevision()
      Return the build revision and date from the routerconsole.war manifest.
      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

      static String applyRewrites(String msg, String[][] rewrites)
      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 null
      rewrites - {needle, replacement} pairs, applied in array order
      Returns:
      the rewritten text
    • formatMessages

      private String formatMessages(List<String> msgs)
      Formats in forward order.
      Parameters:
      msgs - the captured log messages, rendered newest first
      Returns:
      the HTML table-cell fragment, or a "no log messages" notice when the list is empty
    • 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 exist
      utf8 - true for utf-8, false for system locale
      maxNumLines - max number of lines (greater than zero)
      skipLines - number of lines to skip, or zero
      buf - 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

      private String _c(String s)
      Translate a string from the core bundle.
      Parameters:
      s - the string to translate
      Returns:
      the translated string
    • isAdvanced

      public boolean isAdvanced()
      Reports whether advanced mode is enabled for this console.
      Overrides:
      isAdvanced in class HelperBase
      Returns:
      true if the advanced-mode property is set, false otherwise
    • compareLogLines

      private static int compareLogLines(String a, String b)
      Compare two log lines by timestamp (first space-delimited token) then content.
      Parameters:
      a - the first log line to compare
      b - the second log line to compare
      Returns:
      negative if a sorts before b, zero for equal, positive if a sorts after