All Implemented Interfaces:
RequestLog, LifeCycle

public class I2PRequestLogextends AbstractLifeCycle implements RequestLog
This RequestLog implementation outputs logs in the pseudo-standard NCSA common log format. Configuration options allow a choice between the standard Common Log Format (as used in the 3 log format) and the Combined Log Format (single log format). This log format can be output by most web servers, and almost all web log analysis software can understand these formats. ** I2P Mods ** For Jetty 5, this extended NCSARequestLog to override log() to put in the requestor's destination hash, instead of 127.0.0.1, which is placed in the X-I2P-DestHash field in the request headers by I2PTunnelHTTPServer. But we also had to modify NCSARequestLog to do so, to change private fields to protected. So that we will work with system Jetty 6 packages, we just copy the whole thing and modify log() as required.
  • Field Details

    • _filename

      private String _filename
      File name of the request log.
    • _extended

      private boolean _extended
      True for the extended log format.
    • _append

      private boolean _append
      True to append to an existing log file.
    • _retainDays

      private int _retainDays
      Days of rotated log files kept.
    • _closeOut

      private boolean _closeOut
      True to log a final entry when closing.
    • _preferProxiedForAddress

      private boolean _preferProxiedForAddress
      True to prefer the proxied remote address.
    • _logDateFormat

      private String _logDateFormat
      Date format of the log entries.
    • _filenameDateFormat

      private String _filenameDateFormat
      Date format appended to the log file name.
    • _logLocale

      private Locale _logLocale
      Locale used for the log dates.
    • _logTimeZone

      private String _logTimeZone
      Time zone of the log dates.
    • _ignorePaths

      private String[] _ignorePaths
      Request paths excluded from the log.
    • _logLatency

      private boolean _logLatency
      True to log the request latency.
    • _logCookies

      private boolean _logCookies
      True to log the request cookies.
    • _logServer

      private boolean _logServer
      True to log the server name and port.
    • _b64

      private boolean _b64
      True to write the log entries base64 encoded.
    • _out

      private transient OutputStream _out
      Stream the log entries are written to.
    • _fileOut

      private transient OutputStream _fileOut
      The underlying file stream.
    • _logDateCache

      private transient DateCache _logDateCache
      Cache of the formatted request dates.
    • _ignorePathMap

      private transient PathMappings<String> _ignorePathMap
      Mappings of the ignored request paths.
    • _writer

      private transient Writer _writer
      Writer for the formatted log entries.
    • _buffers

      private transient ArrayList<Utf8StringBuilder> _buffers
      Buffers holding the log entry fields.
    • _copy

      private transient char[] _copy
      Scratch buffer for copying between buffers.
  • Constructor Details

    • I2PRequestLog

      public I2PRequestLog()
      I2PRequestLog.
    • I2PRequestLog

      public I2PRequestLog(String filename)
      Create a request log writing to the named file.
      Parameters:
      filename - the file to write to, in any format RolloverFileOutputStream accepts
  • Method Details

    • setFilename

      public void setFilename(String filename)
      Redirect the log to another file.
      Parameters:
      filename - the file to write to, in any format RolloverFileOutputStream accepts; null is ignored
    • getFilename

      public String getFilename()
      The file the log is currently writing to.
      Returns:
      the log filename
    • getDatedFilename

      public String getDatedFilename()
      The log filename with any date tokens expanded.
      Returns:
      the filename in use right now, or the undated name when the log is not rolling over
    • setLogDateFormat

      public void setLogDateFormat(String format)
      If not set, the pre-formated request timestamp is used.
      Parameters:
      format - Format for the timestamps in the log file.
    • getLogDateFormat

      public String getLogDateFormat()
      The format used to timestamp each entry.
      Returns:
      the date format, or null to use the timestamp jetty already formatted
    • setLogLocale

      public void setLogLocale(Locale logLocale)
      Set the locale timestamps are rendered in.
      Parameters:
      logLocale - the locale, or null for the platform default
    • getLogLocale

      public Locale getLogLocale()
      The locale timestamps are rendered in.
      Returns:
      the locale, or null for the platform default
    • setLogTimeZone

      public void setLogTimeZone(String tz)
      Set the time zone timestamps are rendered in.
      Parameters:
      tz - the time zone ID, or null for the platform default
    • getLogTimeZone

      public String getLogTimeZone()
      The time zone timestamps are rendered in.
      Returns:
      the time zone ID, or null for the platform default
    • setRetainDays

      public void setRetainDays(int retainDays)
      Set how many days of rotated logs are kept.
      Parameters:
      retainDays - the retention period in days
    • getRetainDays

      public int getRetainDays()
      How many days of rotated logs are kept.
      Returns:
      the retention period in days
    • setExtended

      public void setExtended(boolean extended)
      Select the extended, combined log format.
      Parameters:
      extended - true for the extended format
    • isExtended

      public boolean isExtended()
      Whether the extended, combined log format is in use.
      Returns:
      true when the extended format is selected
    • setAppend

      public void setAppend(boolean append)
      Choose whether output appends to or replaces an existing file.
      Parameters:
      append - true to append
    • isAppend

      public boolean isAppend()
      Whether output is appended to an existing file rather than replacing it.
      Returns:
      true when appending
    • setIgnorePaths

      public void setIgnorePaths(String[] ignorePaths)
      Set the request paths to leave out of the log.
      Parameters:
      ignorePaths - the paths to exclude, or null to log everything
    • getIgnorePaths

      public String[] getIgnorePaths()
      The request paths left out of the log.
      Returns:
      the ignored paths, or null when nothing is excluded
    • setLogCookies

      public void setLogCookies(boolean logCookies)
      Record whether cookie headers are logged.
      Parameters:
      logCookies - true to log cookies
    • getLogCookies

      public boolean getLogCookies()
      Whether cookie headers are recorded.
      Returns:
      true when cookies are logged
    • getLogServer

      public boolean getLogServer()
      Whether the server identity is recorded in each entry.
      Returns:
      true when the server field is logged
    • setLogServer

      public void setLogServer(boolean logServer)
      Record whether the server field is logged.
      Parameters:
      logServer - true to log the server identity
    • setLogLatency

      public void setLogLatency(boolean logLatency)
      Record whether request latency is logged.
      Parameters:
      logLatency - true to log latency
    • getLogLatency

      public boolean getLogLatency()
      Whether request latency is recorded.
      Returns:
      true when latency is logged
    • setPreferProxiedForAddress

      public void setPreferProxiedForAddress(boolean preferProxiedForAddress)
      Record whether proxied destinations are preferred for an address.
      Parameters:
      preferProxiedForAddress - true to prefer the proxied destination
    • setB64

      public void setB64(boolean b64)
      Choose the base used to encode destination hashes in the log.
      Parameters:
      b64 - true to log in base 64, false for base 32
    • log

      public void log(Request request, Response response)
      Write one request out in the configured format.
      Specified by:
      log in interface RequestLog
      Parameters:
      request - the request being logged
      response - the response being logged
    • logExtended

      protected void logExtended(Request request, Writer writer) throws IOException
      Write the extended fields: the referrer and the user agent.
      Parameters:
      request - the request being logged
      writer - where the log entry is written
      Throws:
      IOException - if the writer fails
    • doStart

      protected void doStart() throws Exception
      Open the log file and build the timestamp cache.
      Overrides:
      doStart in class AbstractLifeCycle
      Throws:
      Exception - if the log file cannot be opened
    • doStop

      protected void doStop() throws Exception
      Flush and close the log file.
      Overrides:
      doStop in class AbstractLifeCycle
      Throws:
      Exception - if the log file cannot be closed
    • getFilenameDateFormat

      public String getFilenameDateFormat()
      The date pattern used to name rotated files.
      Returns:
      the filename date format
    • setFilenameDateFormat

      public void setFilenameDateFormat(String logFileDateFormat)
      Set the log file date format. See RolloverFileOutputStream(String, boolean, int, TimeZone, String, String) Set the date pattern used to name rotated files.
      Parameters:
      logFileDateFormat - the pattern passed to RolloverFileOutputStream