How to enable application logging using the iOS SDK

The Logging module of the AirWatch SDK allows developers to instrument their applications to discover bugs or any issues when the application is deployed to users. 

The AirWatch SDK Logging provides the following types of logs:

Setting

Description

Crash Logs

This type of log captures data from an application the next time the application runs after it crashes. These logs are automatically collected and uploaded to the AirWatch Admin Console without the need for extra code in the SDK application.

Application Logs

This type of log captures information about an application. You set the log level in the default SDK profiles section, Groups & Settings > All Settings > Apps > Settings and Policies > Settings > Logging. You must add code into the application to upload these logs to the AirWatch Admin Console.

Device Logs

This type of log captures information on devices using NSLog statements from all the applications running on the device. They provide some context of what else is happening on the device when an issue arises. You must add code into the application to upload them to the AirWatch Admin Console.

Note: You must code the logging level and set this option in the AirWatch Admin Console. This configuration ensures that your network is not burdened with unwanted logging activity. 

 

Implementation in Xcode for Application Device Logs

You must set the outputDestinationMask on AWLog's sharedInstance before any use of logging can take place. Use the following string to enable logging:

self.outputDestinationMask =

AWLogOutputDestinationDeviceConsole|AWLogOutputDestinationLogFile;

 

Note: This can go into your application's AppDelegate file. 

 

There are four macros that follow the same format as the well known NSLog(...) macro in iOS. Each macro will record an event for the four different logging levels:

  • Verbose - AWLogVerbose
  • Info - AWLogInfo
  • Warning - AWLogWarning
  • Error - AWLogError

To implement an example that showcases the logging levels, set up a UI page similar to the following: 

1.png

 

Next, implement a method called sendApplicationLogButtonPressed to handle the "Send Application Log" button. Similarly, sendDeviceLogButtonPressed will handle the "Send Device Log" button. The following mappings show which methods are called from which buttons (w/format method() : button title):

  • logVerbose() : Verbose
  • logInfo() : Info
  • logWarning() : Warning
  • logError() : Error
  • checkRequestLogCmd() : Check for Request Log Command

An example is as follows:

2.png

 

You also have the ability to add a label above that denotes the Logging Level. The following code can be used to implement this method:

3.png

 

 

Implementation in Xcode for Crash Log Reporting

For application crash logs, the AwCrashLogReporter API is used. See the code below for an example. 

Note: The debugger catches the signal before AwCrashTracker is able to. Due to this, the tracker cannot write the crash log to the disk. A workaround is to stop the debugger, run the app from the device, crash the app, and then run the debugger again. You will now be able to step through the crash reporting code. An example is as follows:

Screen_Shot_2015-08-31_at_1.57.07_PM.png

 

Finishing Steps

You now have the ability to customize the logging ability of your application in order to get a better view of what is going on while it runs. Make sure to choose your logging level appropriately in the SDK profile from the spectrum or recording options that follow:

Setting

Description

Error

Records only errors. An error displays failures in processes such as a failure to look up UIDs or an unsupported URL.

Warning

 

Records errors and warnings. A warning displays a possible issue with processes such as bad response codes and invalid token authentications.

Information

Records a significant amount of data for informational purposes. An information logging level displays general processes as well as warning and error messages.

Verbose

Records all data to help with troubleshooting. This option is not available for all functions.

 

Note: The AirWatch Admin Console reports the messages that match the configured logging level plus any logs with a higher critical status. For example, if you set the logging level to Warning, messages with a Warning and Error level display in the AirWatch Admin Console. 

Have more questions? Submit a request

0 Comments

Article is closed for comments.