Package org.microproxy.extras
Class ActivityLogger
java.lang.Object
org.microproxy.ActivityTrackerAdapter
org.microproxy.extras.ActivityLogger
- All Implemented Interfaces:
ActivityTracker
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionActivityLogger(AccessLogFormat format, Consumer<String> sink) Logs each line informattosink.ActivityLogger(LogFormat logFormat) Logs in a preset format to theSystem.Loggernamedorg.microproxy.extras.ActivityLogger.ActivityLogger(LogFormat logFormat, Consumer<String> sink) Logs each line in a preset format tosink, e.g. a file writer. -
Method Summary
Modifier and TypeMethodDescriptionstatic ActivityLogger.Builderbuilder()Returns a builder of an access logger.filter()Returns the filter that decides which records are written.voidflowEnded(FlowRecord record) 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 (afterActivityTracker.responseCompleted(org.microproxy.FlowContext, org.microproxy.http.HttpResponse), when that was called), and aCONNECTtunnel, 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.format()Returns the format of the lines.Returns the preset this logger writes, ornullfor a custom format.protected voidWrites a finished line.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.microproxy.ActivityTracker
bytesReceivedFromClient, bytesReceivedFromServer, bytesSentToClient, bytesSentToServer, clientConnected, clientDisconnected, clientSSLHandshakeStarted, clientSSLHandshakeSucceeded, connectionExceptionCaught, connectionTimedOut, requestReceivedFromClient, requestSentToServer, responseCompleted, responseReceivedFromServer, responseSentToClient, responseSentToClient, serverConnected, serverConnectionExceptionCaught, serverDisconnected, tlsHandshakeFailed, transparentQuicFlowDecided
-
Constructor Details
-
ActivityLogger
Logs in a preset format to theSystem.Loggernamedorg.microproxy.extras.ActivityLogger.- Parameters:
logFormat- the access log format
-
ActivityLogger
Logs each line in a preset format tosink, e.g. a file writer.- Parameters:
logFormat- the access log formatsink- the consumer receiving each formatted log entry
-
ActivityLogger
Logs each line informattosink.- Parameters:
format- the access log formatsink- the consumer receiving each formatted log entry, ornullfor theSystem.Logger
-
-
Method Details
-
builder
Returns a builder of an access logger.- Returns:
- a builder of an access logger
-
getLogFormat
Returns the preset this logger writes, ornullfor a custom format.- Returns:
- the preset this logger writes, or
nullfor a custom format
-
format
Returns the format of the lines.- Returns:
- the format of the lines
-
filter
Returns the filter that decides which records are written.- Returns:
- the filter that decides which records are written
-
flowEnded
Description copied from interface:ActivityTrackerCalled 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 (afterActivityTracker.responseCompleted(org.microproxy.FlowContext, org.microproxy.http.HttpResponse), when that was called), and aCONNECTtunnel, 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()'sFlowContext.failure()andFlowContext.responseFlags()are final then.- Parameters:
record- the finished exchange or flow
-
log
Writes a finished line. Override to send lines elsewhere.- Parameters:
line- the formatted log entry
-