public final class LoggingEventListener extends EventListener
The format of the logs created by this class should not be considered stable and may change slightly between releases. If you need a stable logging format, use your own event listener.
Modifier and Type | Class and Description |
---|---|
static class |
LoggingEventListener.Factory |
Modifier and Type | Field and Description |
---|---|
private HttpLoggingInterceptor.Logger |
logger |
private long |
startNs |
NONE
Modifier | Constructor and Description |
---|---|
private |
LoggingEventListener(HttpLoggingInterceptor.Logger logger) |
Modifier and Type | Method and Description |
---|---|
void |
callEnd(Call call)
Invoked immediately after a call has completely ended.
|
void |
callFailed(Call call,
java.io.IOException ioe)
Invoked when a call fails permanently.
|
void |
callStart(Call call)
Invoked as soon as a call is enqueued or executed by a client.
|
void |
connectEnd(Call call,
java.net.InetSocketAddress inetSocketAddress,
java.net.Proxy proxy,
Protocol protocol)
Invoked immediately after a socket connection was attempted.
|
void |
connectFailed(Call call,
java.net.InetSocketAddress inetSocketAddress,
java.net.Proxy proxy,
Protocol protocol,
java.io.IOException ioe)
Invoked when a connection attempt fails.
|
void |
connectionAcquired(Call call,
Connection connection)
Invoked after a connection has been acquired for the
call . |
void |
connectionReleased(Call call,
Connection connection)
Invoked after a connection has been released for the
call . |
void |
connectStart(Call call,
java.net.InetSocketAddress inetSocketAddress,
java.net.Proxy proxy)
Invoked just prior to initiating a socket connection.
|
void |
dnsEnd(Call call,
java.lang.String domainName,
java.util.List<java.net.InetAddress> inetAddressList)
Invoked immediately after a DNS lookup.
|
void |
dnsStart(Call call,
java.lang.String domainName)
Invoked just prior to a DNS lookup.
|
private void |
logWithTime(java.lang.String message) |
void |
requestBodyEnd(Call call,
long byteCount)
Invoked immediately after sending a request body.
|
void |
requestBodyStart(Call call)
Invoked just prior to sending a request body.
|
void |
requestFailed(Call call,
java.io.IOException ioe)
Invoked when a request fails to be written.
|
void |
requestHeadersEnd(Call call,
Request request)
Invoked immediately after sending request headers.
|
void |
requestHeadersStart(Call call)
Invoked just prior to sending request headers.
|
void |
responseBodyEnd(Call call,
long byteCount)
Invoked immediately after receiving a response body and completing reading it.
|
void |
responseBodyStart(Call call)
Invoked just prior to receiving the response body.
|
void |
responseFailed(Call call,
java.io.IOException ioe)
Invoked when a response fails to be read.
|
void |
responseHeadersEnd(Call call,
Response response)
Invoked immediately after receiving response headers.
|
void |
responseHeadersStart(Call call)
Invoked just prior to receiving response headers.
|
void |
secureConnectEnd(Call call,
Handshake handshake)
Invoked immediately after a TLS connection was attempted.
|
void |
secureConnectStart(Call call)
Invoked just prior to initiating a TLS connection.
|
private final HttpLoggingInterceptor.Logger logger
private long startNs
private LoggingEventListener(HttpLoggingInterceptor.Logger logger)
public void callStart(Call call)
EventListener
This will be invoked only once for a single Call
. Retries of different routes
or redirects will be handled within the boundaries of a single callStart and EventListener.callEnd(okhttp3.Call)
/EventListener.callFailed(okhttp3.Call, java.io.IOException)
pair.
callStart
in class EventListener
public void dnsStart(Call call, java.lang.String domainName)
EventListener
Dns.lookup(String)
.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different host.
If the Call
is able to reuse an existing pooled connection, this method will not be
invoked. See ConnectionPool
.
dnsStart
in class EventListener
public void dnsEnd(Call call, java.lang.String domainName, java.util.List<java.net.InetAddress> inetAddressList)
EventListener
This method is invoked after EventListener.dnsStart(okhttp3.Call, java.lang.String)
.
dnsEnd
in class EventListener
public void connectStart(Call call, java.net.InetSocketAddress inetSocketAddress, java.net.Proxy proxy)
EventListener
This method will be invoked if no existing connection in the ConnectionPool
can be
reused.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address, or a connection is retried.
connectStart
in class EventListener
public void secureConnectStart(Call call)
EventListener
This method is invoked if the following conditions are met:
Call.request()
requires TLS.ConnectionPool
can be reused.This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address, or a connection is retried.
secureConnectStart
in class EventListener
public void secureConnectEnd(Call call, @Nullable Handshake handshake)
EventListener
This method is invoked after EventListener.secureConnectStart(okhttp3.Call)
.
secureConnectEnd
in class EventListener
public void connectEnd(Call call, java.net.InetSocketAddress inetSocketAddress, java.net.Proxy proxy, @Nullable Protocol protocol)
EventListener
If the call
uses HTTPS, this will be invoked after
EventListener.secureConnectEnd(Call, Handshake)
, otherwise it will invoked after
EventListener.connectStart(Call, InetSocketAddress, Proxy)
.
connectEnd
in class EventListener
public void connectFailed(Call call, java.net.InetSocketAddress inetSocketAddress, java.net.Proxy proxy, @Nullable Protocol protocol, java.io.IOException ioe)
EventListener
If the call
uses HTTPS, this will be invoked after EventListener.secureConnectEnd(Call,
Handshake)
, otherwise it will invoked after EventListener.connectStart(Call, InetSocketAddress,
Proxy)
.
connectFailed
in class EventListener
public void connectionAcquired(Call call, Connection connection)
EventListener
call
.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
connectionAcquired
in class EventListener
public void connectionReleased(Call call, Connection connection)
EventListener
call
.
This method is always invoked after EventListener.connectionAcquired(Call, Connection)
.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
connectionReleased
in class EventListener
public void requestHeadersStart(Call call)
EventListener
The connection is implicit, and will generally relate to the last
EventListener.connectionAcquired(Call, Connection)
event.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
requestHeadersStart
in class EventListener
public void requestHeadersEnd(Call call, Request request)
EventListener
This method is always invoked after EventListener.requestHeadersStart(Call)
.
requestHeadersEnd
in class EventListener
request
- the request sent over the network. It is an error to access the body of this
request.public void requestBodyStart(Call call)
EventListener
The connection is implicit, and will generally relate to the last
EventListener.connectionAcquired(Call, Connection)
event.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
requestBodyStart
in class EventListener
public void requestBodyEnd(Call call, long byteCount)
EventListener
This method is always invoked after EventListener.requestBodyStart(Call)
.
requestBodyEnd
in class EventListener
public void requestFailed(Call call, java.io.IOException ioe)
EventListener
This method is invoked after EventListener.requestHeadersStart(okhttp3.Call)
or EventListener.requestBodyStart(okhttp3.Call)
. Note
that request failures do not necessarily fail the entire call.
requestFailed
in class EventListener
public void responseHeadersStart(Call call)
EventListener
The connection is implicit, and will generally relate to the last
EventListener.connectionAcquired(Call, Connection)
event.
This can be invoked more than 1 time for a single Call
. For example, if the response
to the Call.request()
is a redirect to a different address.
responseHeadersStart
in class EventListener
public void responseHeadersEnd(Call call, Response response)
EventListener
This method is always invoked after EventListener.responseHeadersStart(okhttp3.Call)
.
responseHeadersEnd
in class EventListener
response
- the response received over the network. It is an error to access the body of
this response.public void responseBodyStart(Call call)
EventListener
The connection is implicit, and will generally relate to the last
EventListener.connectionAcquired(Call, Connection)
event.
This will usually be invoked only 1 time for a single Call
,
exceptions are a limited set of cases including failure recovery.
responseBodyStart
in class EventListener
public void responseBodyEnd(Call call, long byteCount)
EventListener
Will only be invoked for requests having a response body e.g. won't be invoked for a websocket upgrade.
This method is always invoked after EventListener.requestBodyStart(Call)
.
responseBodyEnd
in class EventListener
public void responseFailed(Call call, java.io.IOException ioe)
EventListener
This method is invoked after EventListener.responseHeadersStart(okhttp3.Call)
or EventListener.responseBodyStart(okhttp3.Call)
.
Note that response failures do not necessarily fail the entire call.
responseFailed
in class EventListener
public void callEnd(Call call)
EventListener
This method is always invoked after EventListener.callStart(Call)
.
callEnd
in class EventListener
public void callFailed(Call call, java.io.IOException ioe)
EventListener
This method is always invoked after EventListener.callStart(Call)
.
callFailed
in class EventListener
private void logWithTime(java.lang.String message)