Class ActivityLogger

java.lang.Object
org.microproxy.ActivityTrackerAdapter
org.microproxy.extras.ActivityLogger
All Implemented Interfaces:
ActivityTracker

public class ActivityLogger extends ActivityTrackerAdapter
An ActivityTracker that writes one access-log line per finished exchange or flow (ActivityTracker.flowEnded(org.microproxy.FlowRecord)), in an AccessLogFormat: one of the LogFormat presets, or an Envoy-compatible format string or JSON dictionary. An AccessLogFilter may leave records out. Add it with bootstrap.plusActivityTracker(new ActivityLogger(LogFormat.CLF)), or build one:

 ActivityLogger.builder()
         .format(LogFormat.envoy("%START_TIME% %REQ(:METHOD)% %RESPONSE_CODE% %RESPONSE_FLAGS%"))
         .filter(AccessLogFilter.parse("status>=400 || response_flag"))
         .sink(lines::add)
         .build();
 

A line is written when the exchange is over: once its response has been written, or when it was abandoned (with the flags that say why); for a CONNECT tunnel, a SOCKS client, a WebSocket session, a CONNECT-UDP flow or a relayed QUIC flow, when it closes. Lines go to the System.Logger named after this class at INFO, or to the sink.

  • Constructor Details

    • ActivityLogger

      public ActivityLogger(LogFormat logFormat)
      Logs in a preset format to the System.Logger named org.microproxy.extras.ActivityLogger.
      Parameters:
      logFormat - the access log format
    • ActivityLogger

      public ActivityLogger(LogFormat logFormat, Consumer<String> sink)
      Logs each line in a preset format to sink, e.g. a file writer.
      Parameters:
      logFormat - the access log format
      sink - the consumer receiving each formatted log entry
    • ActivityLogger

      public ActivityLogger(AccessLogFormat format, Consumer<String> sink)
      Logs each line in format to sink.
      Parameters:
      format - the access log format
      sink - the consumer receiving each formatted log entry, or null for the System.Logger
  • Method Details

    • builder

      public static ActivityLogger.Builder builder()
      Returns a builder of an access logger.
      Returns:
      a builder of an access logger
    • getLogFormat

      public LogFormat getLogFormat()
      Returns the preset this logger writes, or null for a custom format.
      Returns:
      the preset this logger writes, or null for a custom format
    • format

      public AccessLogFormat format()
      Returns the format of the lines.
      Returns:
      the format of the lines
    • filter

      public AccessLogFilter filter()
      Returns the filter that decides which records are written.
      Returns:
      the filter that decides which records are written
    • flowEnded

      public void flowEnded(FlowRecord record)
      Description copied from interface: ActivityTracker
      Called once when an exchange or a flow is over, with what an access log needs to know about it: an HTTP exchange whose response has been written or that was abandoned (after ActivityTracker.responseCompleted(org.microproxy.FlowContext, org.microproxy.http.HttpResponse), when that was called), and a CONNECT tunnel, a SOCKS client's tunnel, a WebSocket session, a TCP-hook tunnel, a CONNECT-UDP flow, or a transparent QUIC flow that was relayed or intercepted stream by stream, when it closes. FlowRecord.context()'s FlowContext.failure() and FlowContext.responseFlags() are final then.
      Parameters:
      record - the finished exchange or flow
    • log

      protected void log(String line)
      Writes a finished line. Override to send lines elsewhere.
      Parameters:
      line - the formatted log entry