Welcome to Instabug's Documentation!
Here you'll find a comprehensive technical guide
to help you start working with the Instabug SDK efficiently.

Get Started

Report Logs

This section covers how Instabug automatically attaches console logs, verbose logs, and all steps made by your users before a bug report is sent for iOS apps.

Privacy Policy

It is highly recommended to mention in your privacy policy that you may be collecting logging data in order to assist with troubleshooting bugs.

A variety of log types are sent with each crash or bug report. They appear within each report in your Instabug dashboard, as shown below. Log collection stops when Instabug is shown.

We support the following types of logs:

An example of the expanded logs view from your dashboard.

An example of the expanded logs view from your dashboard.

User Steps

Instabug can help you reproduce issues by tracking each step a user has taken until a report is sent. Note that the maximum number of user steps sent with each report is 100.

User Steps are formatted as follows: Event in label of type class in controller
For example: Tap in UITableViewCellContentView in ViewController

  • The type of events captured are tap, long press, force touch, swipe, scroll and pinch.
  • We also capture life cycle events such as entering background, entering foreground, became active, resign active, and memory warning.
  • Label refers to the label of the object that contains the event.
  • Class refers to the class of the object that contains the event.
  • Controller refers to the view that contained the event.
An example of the expanded logs view filtered by User Steps.

An example of the expanded logs view filtered by User Steps.

You can disable User Steps with the following method.

Instabug.trackUserSteps = false
Instabug.trackUserSteps = NO;

To be able to capture User Steps, we need to do method swizzling. We take an approach to swizzling that is absolutely safe and does not impact your app negatively in any way. For more details, you can check here.

Repro Steps

Repro Steps show you all of the interactions a user makes with your app up until a bug or crash is reported, grouped by app view. For each view that a user visits, all of the steps that they commit within those views are captured and displayed as a log, grouped by view.

An example of Visual Repro Steps in the Instabug dashboard.

An example of Visual Repro Steps in the Instabug dashboard.

This feature is enabled by default starting from the Silver Plan. You can control it through the following API.

Instabug.reproStepsMode = .enabledWithNoScreenshots
Instabug.reproStepsMode = IBGUserStepsModeEnabledWithNoScreenshots;

Here are the possible arguments.

.enabledWithNoScreenshots
.disable
IBGUserStepsModeEnabledWithNoScreenshots;
IBGUserStepsModeDisable;

Network Logs

Instabug automatically logs all network requests performed by your app. Requests details, along with their responses, are sent with each report. Instabug will also show you an alert at the top of the bug report in your dashboard when network requests have timed-out or taken too long to complete. Note that the maximum number of network logs sent with each report is 1,000.

An example of network request logs in the Instabug dashboard.

An example of network request logs in the Instabug dashboard.

Omitting Requests

You can omit requests from being logged based on either their request or response details.

+ [Instabug setNetworkLoggingRequestFilterPredicate:responseFilterPredicate:] allows you to specify two predicates to be evaluated against every request and response to determine if the request should be included in logs or not.

let path = "/products"
let requestPredicate = NSPredicate(format: "URL.path MATCHES %@", path)
let responsePredicate = NSPredicate(format: "statusCode >= %d AND statusCode <= %d", 200, 399)
NetworkLogger.setNetworkLoggingRequestFilterPredicate(requestPredicate, responseFilterPredicate: responsePredicate)
NSString *path = @"/products";
NSPredicate *requestPredicate = [NSPredicate predicateWithFormat:@"URL.path MATCHES %@", path];
NSPredicate *responsePredicate = [NSPredicate predicateWithFormat:@"statusCode >= %d AND statusCode <= %d", 200, 399];
[IBGNetworkLogger setNetworkLoggingRequestFilterPredicate:requestPredicate responseFilterPredicate:responsePredicate];

The code above excludes all requests made to URLs that have /products path. It also excludes all responses that have a success and redirection status code, thus only including requests with 4xx and 5xx responses.

requestFilterPredicate is evaluated against an NSURLRequest, while responseFilterPredicate is evaluated against an NSHTTPURLResponse.

Obfuscating Data

Requests

You can obfuscate sensitive user data in requests, like authentication tokens for example, without filtering out the whole request.

NetworkLogger.setRequestObfuscationHandler { (request) -> URLRequest in
    var myRequest:NSMutableURLRequest = request as! NSMutableURLRequest
    let urlString = request.url?.absoluteString
    urlString = obfuscateAuthenticationTokenInString()
    let obfuscatedURL = URL(string: urlString)
    myRequest.url = obfuscatedURL
    return myRequest.copy() as! URLRequest
}
IBGNetworkLogger.requestObfuscationHandler = ^NSURLRequest * _Nonnull(NSURLRequest * _Nonnull request) {
        NSMutableURLRequest *myRequest = [request mutableCopy];
        NSString *urlString = request.URL.absoluteString;
        urlString = [self obfuscateAuthenticationTokenInString:urlString];
        NSURL *obfuscatedURL = [NSURL URLWithString:urlString];
        myRequest.URL = obfuscatedURL;
        return myRequest;
    };

Responses

As with requests, the response object, as well as the response data, can be modified for obfuscation purposes before they are logged.

NetworkLogger.setResponseObfuscationHandler { (data, response, completion) in
    if let data = data {
        let modifiedData = self.modify(data: data)
        let modifiedResponse = self.modify(response: response)
        
        completion(modifiedData, modifiedResponse)
    }
}
[IBGNetworkLogger setResponseObfuscationHandler:^(NSData * _Nullable responseData, NSURLResponse * _Nonnull response, NetworkObfuscationCompletionBlock  _Nonnull returnBlock) {
    NSData *modifiedData = [self obfuscateData:responseData];
    NSURLResponse *modifiedResponse = [self obfuscateResponse:response];
    
    returnBlock(modifiedData, modifiedResponse);
}];

Requests Not Appearing

If your network requests aren't being logged automatically, that probably means you're using a custom NSURLSession or NSURLSessionConfiguration.

To enable logging for your NSURLSession, add the following code.

let configuration = URLSessionConfiguration.ephemeral
NetworkLogger.enableLogging(for: configuration)
let session = URLSession(configuration: configuration)
NSURLSessionConfiguration *configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration;
[IBGNetworkLogger enableLoggingForURLSessionConfiguration:configuration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];

AFNetworking

To enable logging for AFNetworking, create the following class.

// IBGAFURLSessionManager.h

#import <AFNetworking/AFNetworking.h>

@interface IBGAFURLSessionManager : AFURLSessionManager

@end

// IBGAFURLSessionManager.m
  
#import "IBGAFURLSessionManager.h"
#import <Instabug/Instabug.h>

@implementation IBGAFURLSessionManager

- (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration {
		[IBGNetworkLogger enableLoggingForURLSessionConfiguration:configuration];
    
    return [super initWithSessionConfiguration:configuration];
}

@end

Then use IBGAFURLSessionManager to create your requests.

Alamofire

To enable logging for Alamofire, create the following class.

import Alamofire
import Instabug

class IBGSessionManager: Alamofire.SessionManager {
    static let sharedManager: IBGSessionManager = {
        let configuration = URLSessionConfiguration.default
				NetworkLogger.enableLogging(for: configuration)
        configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders
        let manager = IBGSessionManager(configuration: configuration)
        return manager
    }()
}

Then use IBGAFURLSessionManager to create your requests.

Disabling Requests

Network request logging is enabled by default if it's included in your plan. To disable it, use the following method.

NetworkLogger.enabled = false
IBGNetworkLogger.enabled = NO;

Instabug Logs

Instabug Logs are similar to NSLog() and print(), but they have the added benefit of having different verbosity levels. This lets you filter logs based on their verbosity level when viewing a report on your Instabug dashboard. Note that the maximum number of Instabug logs sent with each report is 1,000.

Use Instabug Logs through the following methods.

IBGLog.log("Log statement")
IBGLog.logVerbose("Verbose statement")
IBGLog.logInfo("Info statement")
IBGLog.logWarn("Warning statement")
IBGLog.logDebug("Debug statement")
IBGLog.logError("Error statement")
IBGLogVerbose(@"Verbose log message");
IBGLogDebug(@"Debug log message");
IBGLogInfo(@"Info log message");
IBGLogWarn(@"Warn log message");
IBGLogError(@"Error log message");

Instabug Logs with 3rd Party Loggers

If you use CocoaLumberjack or XCGLogger, you can easily route all your logs to Instabug using our log destinations. Check the instructions on GitHub for CocoaLumberjack and XCGLogger.

Console Logs

Instabug captures all console logs and displays them on your dashboard with each report. Note that the maximum number of console logs sent with each report is 500 statements with an unlimited number of characters for each statement.

Console Logs on iOS 10

Due to the changes that Apple has made to how logging works, we can only capture console logs on iOS versions prior to 10.

To work around this issue, you can add the following snippet to your AppDelegate file but outside the scope of the class to allow Instabug to capture logs automatically on iOS 10.

inline void NSLog(NSString *format, ...) {
    va_list arg_list;
    va_start(arg_list, format);
    IBGNSLogWithLevel(format, arg_list, IBGLogLevelDefault);
    va_end(arg_list);
}

Alternatively, you can replace all your NSLog() and print() statements with IBGLog.

Another workaround in case you are using Swift 3.0 or above is to send console logs through the following print method. Make sure to define this method outside the AppDelegate class scope in the correct place such that it becomes accessible in all your classes.

public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
    let output = items.map { "\($0)" }.joined(separator: separator)
    
    Swift.print(output, terminator: terminator);
    Instabug.ibgLog(output)
}

User Events

You can log custom user events throughout your application and they will automatically be included with each report. Note that the maximum number of user events sent with each report is 1,000.

Instabug.logUserEvent(withName: "Skipped Walkthrough")
[Instabug logUserEventWithName:@"Skipped Walkthrough"];

What's Next

Logs go hand-in-hand with both bug and crash reporting, so why not give those a look? The Session Profiler feature also give you more comprehensive details alongside logs.

Bug Reporting
Crash Reporting
Session Profiler

Report Logs


This section covers how Instabug automatically attaches console logs, verbose logs, and all steps made by your users before a bug report is sent for iOS apps.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.