Class HttpLogger
- All Implemented Interfaces:
HttpFiltersSource
HttpLoggingInterceptor or a mitmproxy flow dump. It is a filters source; add it with
bootstrap.plusFiltersSource(logger), in an HttpFiltersChain, or inside
built filters with HttpFiltersBuilder.log(org.microproxy.extras.HttpLogger):
HttpLogger logger = HttpLogger.builder()
.level(HttpLogger.Level.HEADERS)
.redactQueryParams("token", "api_key")
.build();
MicroProxy.bootstrap().plusFiltersSource(logger).start();
For each exchange it logs the request as the client sent it, with the changes made before it
was forwarded (by the proxy and by filters) when there are any, then the response as the server
sent it, with the changes made before it was delivered, the ResponseSource, the
server's status (FlowContext.upstreamStatus()) and the timings (FlowContext.timings()). Each message is one string handed to the sink, every line starting
with [conn <id> #<n>]: the client connection, as in the proxy's own log lines, and the
exchange's number on it. Responses are logged once they have been delivered in full.
HttpLogger.Level.BASIC and HttpLogger.Level.HEADERS look only at heads, so bodies keep the proxy's
fast path. HttpLogger.Level.BODY reads bodies piece by piece and keeps at most HttpLogger.Builder.maxBodyBytes of each; it never changes what is forwarded. Bodies are decoded (
gzip, deflate, br, zstd, see HttpBodies) when the whole body was
kept, and shown as text in their charset, or summarised when they are binary. With HttpLogger.Builder.contentViews(org.microproxy.contentviews.ContentViews) they are rendered through ContentViews instead where a view
applies: protobuf and gRPC (message by message) as YAML with field numbers, JSON indented, form
data, GraphQL, msgpack. Trailers are shown after the body, and gRPC's status fields explained.
The values of Authorization, Cookie, Set-Cookie and
Proxy-Authorization are replaced with "\u2588\u2588" unless HttpLogger.Builder.redactNothing()
says otherwise. Bodies are not redacted: HttpLogger.Level.BODY logs payloads, with whatever secrets
and personal data they carry.
Lines go to the System.Logger named "org.microproxy.http" at INFO unless a HttpLogger.Builder.sink is given; when that logger is off, the filters are not even created. A sink that
throws is reported once and never disturbs the proxy.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConfigures anHttpLogger.static enumHow messages are written.static enumHow much of each message to log. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default forHttpLogger.Builder.maxBodyBytes.Headers redacted unlessHttpLogger.Builder.redactNothing()is called.static final StringTheSystem.Loggerlines go to without aHttpLogger.Builder.sink.static final StringWhat redacted values are replaced with. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpLogger.Builderbuilder()Starts a logger atHttpLogger.Level.HEADERS, writingHttpLogger.Format.TEXTwith the default redaction.Returns the content view bodies are rendered with ("auto" for the best one).Returns the content views bodies are rendered with, ornullwhen they are not.filterRequest(HttpRequest originalRequest, FlowContext flowContext) Filters that log this exchange, ornullwhen it is not logged: theHttpLogger.Builder.onlypredicate declined it, or the defaultSystem.Loggeris off at INFO.format()Returns the configured log output format.level()Returns the configured logging detail.booleanReturns whether WebSocket frames are logged (atHttpLogger.Level.BODY).intReturns the maximum body bytes retained per log entry.Returns the redacted header names, in lower case.Returns the redacted query parameter names, in lower case.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.microproxy.HttpFiltersSource
getMaximumRequestBufferSizeInBytes, getMaximumResponseBufferSizeInBytes
-
Field Details
-
LOGGER_NAME
TheSystem.Loggerlines go to without aHttpLogger.Builder.sink.- See Also:
-
REDACTED
What redacted values are replaced with.- See Also:
-
DEFAULT_REDACTED_HEADERS
Headers redacted unlessHttpLogger.Builder.redactNothing()is called. -
DEFAULT_MAX_BODY_BYTES
public static final int DEFAULT_MAX_BODY_BYTESThe default forHttpLogger.Builder.maxBodyBytes.- See Also:
-
-
Method Details
-
builder
Starts a logger atHttpLogger.Level.HEADERS, writingHttpLogger.Format.TEXTwith the default redaction.- Returns:
- a new builder with default settings
-
level
Returns the configured logging detail.- Returns:
- the configured logging detail
-
format
Returns the configured log output format.- Returns:
- the configured log output format
-
redactedHeaders
Returns the redacted header names, in lower case.- Returns:
- the redacted header names, in lower case
-
redactedQueryParams
Returns the redacted query parameter names, in lower case.- Returns:
- the redacted query parameter names, in lower case
-
maxBodyBytes
public int maxBodyBytes()Returns the maximum body bytes retained per log entry.- Returns:
- the maximum body bytes retained per log entry
-
contentViews
Returns the content views bodies are rendered with, ornullwhen they are not.- Returns:
- the content views bodies are rendered with, or
nullwhen they are not
-
contentView
Returns the content view bodies are rendered with ("auto" for the best one).- Returns:
- the content view bodies are rendered with ("auto" for the best one)
-
logsWebSocketFrames
public boolean logsWebSocketFrames()Returns whether WebSocket frames are logged (atHttpLogger.Level.BODY).- Returns:
- whether WebSocket frames are logged (at
HttpLogger.Level.BODY)
-
filterRequest
Filters that log this exchange, ornullwhen it is not logged: theHttpLogger.Builder.onlypredicate declined it, or the defaultSystem.Loggeris off at INFO.- Specified by:
filterRequestin interfaceHttpFiltersSource- Parameters:
originalRequest- a copy of the request as received from the clientflowContext- the client connection the request arrived on- Returns:
- the per-request filters, or
nullto leave the request unfiltered
-
toString
-