Logging with CocoaLumberjack and TestFlight

Consider the following situation that happens far too often in mobile app development: You’ve just released an app that works perfectly for you, and you’ve tested it extensively. You’re proud of your accomplishments and submit the app to the world, only to have several emails sent to you from users who have nothing but difficulties in running the app. You send a bug fix release to the App Store, but since you’re still unable to reproduce the problem you’re at the whim of luck and end-user feedback. You can hope your users know how to send you a crash report, but what if the app isn’t actually crashing? Wouldn’t it be great to be able to access your app’s log information from that client to be able to troubleshoot the problems?

In working on Docset Viewer I’ve run up against this very same problem. I’ve solved most of the bugs reported to me, but I still have gotten a few troubling reports that users have gotten into a stuck state where they had to uninstall/reinstall the app to get it to work consistently. Obviously some bad data got stored somewhere that was breaking the app, but until I’m able to find out what it was that was making the app feel ill, I can’t solve the root cause.

With the recent release of TestFlight’s “Live” service, they allow for automatic crash-log reporting and log-file upload support to their cloud-based service. But since the vast majority of my users don’t have any problems using my app, I don’t want to wade through tons of log information. Additionally, during the development of the app I’ll use console logging for my own internal diagnostics, but the high level of verbosity would be overkill when used in a production app. Instead of simply commenting out or deleting log lines when I’m done developing a feature, it would be useful to have a flexible logging solution that would let me develop my code with ease, while still allowing to have certain high-priority log messages make it through to me in production.

I’ve managed to come to a happy medium between ease of use and cloud-based log reporting by combining the excellent CocoaLumberjack library with the TestFlight Live SDK.

What’s TestFlight Live

TestFlight has been around for a while as a solution for simplifying the beta-tester management process.  It includes an SDK that lets you send crash reports and usage information to the web-based service to see which beta testers have installed the app, what issues they’ve encountered, and even provides a method to send feedback to you from within the app.  Recently however they released an update to their service that extends it to become TestFlight Live, which provides crash log reporting and usage analysis for live apps in the App Store.

What’s CocoaLumberjack?

In it’s own words, CocoaLumberjack is “…similar in concept to other popular logging frameworks such as log4j, yet is designed specifically for Objective-C, and takes advantage of features such as multi-threading, grand central dispatch (if available), lockless atomic operations, and the dynamic nature of the Objective-C runtime.” It is faster than plain NSLog, is more flexible through the use of different log levels, and is pluggable for providing additional modes of logging above and beyond simple console logging.

I was introduced to this wonderful framework through the CocoaHTTPServer library which I use in Docset Viewer as well as another upcoming app of mine.  In my apps so far however, I took many of Lumberjack’s more advanced features for granted, only opting to use its different log-levels and per-configuration log targets to customize my app’s behaviour.  For example, on debug builds my app logs at a higher verbosity than on release builds.

This all changed when I released my recent v1.3 update to Docset Viewer.  Between v1.1 and v1.3 I fixed a number of bugs reported by my users, and the app is far more stable as a result. But there are still some hard-to-reproduce issues that are occurring and I need more information to be able to correct them properly.

To get more insights into what’s happening, I used Lumberjack’s custom logger capability to add my own class for reporting log messages to TestFlight.

Using this in your application is easy. You simply need to add the following lines to the beginning of your application:didFinishLaunchingWithOptions: method:

This assumes you have a “DEBUG” definition declared for your debug or adhoc builds which helps prevent log messages filtering into TestFlight unnecessarily.  With this addition, not only will your TestFlight account give you timely information about crashes encountered by your users, but you’ll have access to the log messages that will provide valuable insights into why those crashes occurred.

This is just the tip of the iceberg, and I’m sure there’s more areas where TestFlight and Lumberjack can be used to enhance your ability to quickly fix bugs.

Tags:

About Michael Nachbaur

iOS app developer, livin' the dream. Working from wherever I find myself; Hawaii, Santa Monica, Vancouver, and elsewhere.

3 Responses to “Logging with CocoaLumberjack and TestFlight”

  1. Dominique April 30, 2012 2:20 pm
    #

    Oh !
    Thank you for these precious tips. The case you described is strictly the same I am confronted with !

  2. Dominique May 1, 2012 12:24 am
    #

    I use NSLogger tool for desktop logging : NSlogger , https://github.com/fpillet/NSLogger
    There is a NSLogger backend for CocoaLumberjack too : https://github.com/steipete/NSLogger-CocoaLumberjack-connector

    In a project, several logs are defined in the prefix header file (prefix.pch) : they are enable only while debugging using “DEBUG” definition.

    #ifdef DEBUG
    #define LOG_EVENT(level, …) LogMessageF(__FILE__,__LINE__,__FUNCTION__,@”evenement”,level,__VA_ARGS__)
    #else
    #define LOG_EVENT(…) do{}while(0)
    #endif

    Your post gave me an idea : in non DEBUG mode let’s log to TestFlight instead of doing nothing !

Trackbacks/Pingbacks

  1. CocoaLumberjack и TestFlight, как средство против багов | Progalina - April 8, 2012

    [...] [nchbr] Tweet (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/ru_RU/all.js#xfbml=1&appId=367905153223435"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); VK.init({apiId: 2802152, onlyWidgets: true}); VK.Widgets.Like('vk_like_69', {type: 'mini', pageTitle: 'CocoaLumberjack и TestFlight, как средство против багов', pageUrl:'http://progalina.ru/news/cocoalumberjack-testflight/', verb: '0'}, 69); Posted Апр 08 , 2012 Categorized: Новости Tagged: ios, logging [...]