For the complete documentation index, see llms.txt. This page is also available as Markdown.

Network Logging - Android

API reference for network logging in Android with Luciq. Configure network monitoring APIs to capture HTTP requests and responses in your Android app.

Network logs are automatically collected by Luciq when possible. There are many way to configure and manipulate these logs from the code.

Logging HttpUrlConnection Requests

To log network requests, use LuciqNetworkLog then use the following method at the HttpUrlConnection, requestBody and responseBody. A more detailed example can be found here.

Logging HttpUrlConnection Requests

LuciqNetworkLog networkLog = new LuciqNetworkLog();
networkLog.Log(urlConnection, requestBody, responseBody);
LuciqNetworkLog networkLog = new LuciqNetworkLog()
networkLog.Log(urlConnection, requestBody, responseBody)

Logging Okhttp Requests

In order to log Okhttp requests, first make sure that you compiled Luciq with a network interceptor. By adding the following to your Gradle: implementation 'com.luciq.library:luciq-with-okhttp-interceptor:8+'

An example of the implementation can be found on the right hand side of this section.

Logging Okhttp Requests

First, start by compiling Luciq with a network interceptor using this API.

implementation 'com.luciq.library:luciq-with-okhttp-interceptor:11.5.4'

Then to log Oktthp requests, use the LuciqOkhttpInterceptor as shown in the following example.

LuciqOkhttpInterceptor luciqOkhttpInterceptor = new LuciqOkhttpInterceptor();

OkHttpClient client = new OkHttpClient.Builder()
    .addInterceptor(interceptor)
    .addInterceptor(luciqOkhttpInterceptor)
    .build();
val luciqOkhttpInterceptor = LuciqOkhttpInterceptor()

val client = OkHttpClient.Builder()
         .addInterceptor(interceptor)
         .addInterceptor(luciqOkhttpInterceptor)
         .build()

Modifying Requests

If you want to modify a network request before it gets sent to the dashboard, you may follow the steps below.

  1. Create a NetworkLogListener object and modify the captured network log as shown below.

  1. Register the created NetworkLogListener to your LuciqOkHttpInterceptor object. This can be done through two different methods:

a. Pass it in the constructor.

b. Call registerNetworkLogsListener method on LuciqOkhttpInterceptor object.

If you want to remove the network listener, you can do so using this API.

Identifying Cancelled Requests

NetworkLogSnapshot.isCanceled is true when your app cancelled an OkHttp request before it completed, such as a Call.cancel(). Cancelled requests are captured as failures; return null from the listener to drop them.

isCanceled is available starting from SDK v19.10.1 and applies to OkHttp requests only — logs captured through UrlConnection, WebView, or gRPC always report false.

The property is read-only, is never sent to the dashboard, and is not carried over by copy() — read it before creating a modified copy.

Last updated