When debugging your mobile application, logging can provide critical information. A few problems arise from the simplicity of iOS’s logging interface. The built-in method,
NSLog, is mainly a development tool, but when left in release code it will still be executed. Removing
NSLog calls before release can be a tiresome process, but leaving them in will slow down your application.
A nice feature of Android logging is the multiple log levels. iOS only has one, making it impossible to choose on the fly which log statements should be shown. A selective level of output helps display what’s most important.
Lumberjack brings some of this flexibility to iOS logging. Log levels can be customized per file and easily turned off. Multiple logging events, such as saving to file and outputting to the console, can be executed simultaneously.
For simple logging, a substantial performance gain can be seen over
NSLog. Lumberjack benchmarks at up to 32x faster for asynchronous logging.
It is very easy to get started using Lumberjack in your iOS project. In your
AppDelegate, simply do the following:
DDTTYLogger.h and add the following line to
[DDLog addLogger:[DDTTYLogger sharedInstance]];
In any method you wish to use a log statement, you must import
DDLog.h and you must have access to a log level variable:
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
Finally, you can call the log function using one of the following using the same parameters as you would using
NSLog(NSString *format, ...):
- log level support
- easily switch off logging for release
- optional logging to file
- increased performance
- need to import headers
- must re-run the application to change the log level
About the Author
BiographyMore Content by Pivotal Labs