Package org.microproxy.extras
Class AccessLogFormat
java.lang.Object
org.microproxy.extras.AccessLogFormat
An access-log line format, compatible with Envoy's access-log command operators: a format string
such as
[%START_TIME%] "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%"
%RESPONSE_CODE% %RESPONSE_FLAGS%, or a JSON dictionary whose values are format strings. The
format is parsed once, into an array of pieces that each render one literal or one operator, so
rendering a FlowRecord needs no parsing and no regular expressions.
An operator whose value is not available (a missing header, no upstream, a tunnel's response
code details before it has any) renders -, as does an operator this class does not know.
%OPERATOR(...):N% truncates the value to N characters. In text formats, control
characters in values are escaped (\n, \t, ), so a value cannot
break a line; %% is a literal %. In the JSON form, a value that is a single
operator keeps the operator's type: numbers for codes, sizes and durations, true or
false for flags, null when unavailable; other values are strings.
See the access-log format reference
(docs/reference/access-log-format.md) for the operators.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic AccessLogFormatParses an Envoy format string.static AccessLogFormatenvoyJson(Map)from the JSON text of the dictionary, as the command line passes it:{"status":"%RESPONSE_CODE%","path":"%REQ(:PATH)%"}.static AccessLogFormatA JSON format: one JSON object per line, whose keys are those ofdictionary(in its iteration order) and whose values are rendered from its values: a format string, a nested map, or a number, boolean ornullwritten as it is.format(FlowRecord record) Renders one line forrecord.voidformatTo(FlowRecord record, StringBuilder out) Appends one line forrecordtoout.booleanisJson()Returns whether this is a JSON format.toString()
-
Field Details
-
ENVOY_DEFAULT
Envoy's default access-log format.- See Also:
-
-
Method Details
-
envoy
Parses an Envoy format string. A trailing newline (Envoy's formats end with one) is dropped: the logger writes each line on its own.- Parameters:
format- the format string- Returns:
- the format
-
envoyJson
A JSON format: one JSON object per line, whose keys are those ofdictionary(in its iteration order) and whose values are rendered from its values: a format string, a nested map, or a number, boolean ornullwritten as it is.- Parameters:
dictionary- the keys and their format strings- Returns:
- the format
-
envoyJson
envoyJson(Map)from the JSON text of the dictionary, as the command line passes it:{"status":"%RESPONSE_CODE%","path":"%REQ(:PATH)%"}.- Parameters:
dictionary- a JSON object- Returns:
- the format
- Throws:
IllegalArgumentException- if the text is not a JSON object
-
isJson
public boolean isJson()Returns whether this is a JSON format.- Returns:
- whether this is a JSON format
-
format
Renders one line forrecord.- Parameters:
record- the finished exchange or flow- Returns:
- the line, without a line terminator
-
formatTo
Appends one line forrecordtoout.- Parameters:
record- the finished exchange or flowout- where the line goes
-
toString
-