Skip to content

Network Logs

Appelium supports rich network log capturing. This include structured request and response information like:

  • Headers
  • Payload
  • Duration
  • Status codes

Automatic network requests capturing

By default, logging is automatically enabled for all network requests which use URLSession.shared, URLSessionConfiguration.default and URLSessionConfiguration.ephemeral configuration.

If you wish to enable network logging for any other/custom session configuration you can simply call:

AppeliumFeedback.enableLogging(for: mySessionConfiguration)

Tip

If you are already printing network requests information to the console using NSLog or print statements, you may wish to disable it in order to not to have duplicate logs.

Enable filtering and obfuscation

You can enable custom request filters or implement full obfuscation in case you wish to hide or prevent sensitive information from even getting logged. You can enable this using:

AppeliumFeedback.networkRequestObfuscationHandler = self

And then implement NetworkRequestObfuscationHandler protocol:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
func obfuscateNetworkRequest(_ originalRequest: NetworkRequest) -> NetworkRequest? {
    return NetworkRequest(
        url: originalRequest.url, // Additionally you can remove query params, path, port etc
        httpMethod: originalRequest.httpMethod, // You can modify it as well
        headerFields: nil, // Remove all headers, or pass an `[HTTPHeaderField]` to keep/modify them
        body: nil // Remove the body or modify it
    )
}

func obfuscateNetworkResponse(_ originalResponse: NetworkResponse) -> NetworkResponse? {
    return NetworkResponse(
        url: originalResponse.url, // Additionally you can remove query params, path, port etc
        statusCode: originalResponse.statusCode, // You can modify it as well
        headerFields: nil, // Remove all headers, or pass an `[HTTPHeaderField]` to keep/modify them
        body: nil, // Remove the body or modify it
        error: originalResponse.error
    )
}

Manual request logging

In case you are not using the standard URLSession or you want to capture request that are not automatically captured, Appelium provides you with APIs that will allow you to manually log HTTP requests:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
let token = AppeliumFeedback.logRequestStart(
    url: URL(string: "www.example.com/test")!, 
    method: "GET", 
    headers: headers, 
    body: body
)
AppeliumFeedback.logRequestFinish(
    token: token, 
    statusCode: 201, 
    headers: responseHeaders, 
    data: responseData
)

or in case of an error:

AppeliumFeedback.logRequestError(token: token, error: error)