Original question: What are the alternative logging modules to NSLog for an iOS application? Please explain the pros and cons that you've experienced first hand.
Additional request 1: I did try to use the TestFlight TFLog which also helps with uploading the logs to their server but it seems to be limited when you need logging when app is running in the background. A logging system that helps with rolling/compressing the log files and server uploads would greatly help.
Additional request 2: Another issue of NSLog that some have written about is that Apple does not like it when you submit the app for production.
Thanks.
There's always the printf family of functions, those are generally faster than NSLog, but do not have support for the %@ format specifier for objects.
Lately I've been using the excellent Lumberjack framework for logging, which is asynchronous and will not have a performance impact on your code. It also has tons of customization features for log output formatting.
If you're interested in making your own NSLog variant (a complete replacement), have a look here.
If you don't want to make your own NSLog but would rather customise what the current NSLog can have a look at some of the tricks outlined on this page instead.
Personally, I prefer the redo-NSLog-from-scratch approach as it offers much more control. It does however take quite a bit more time to implement and you have to learn about variable argument lists and their implementation in order to get it working properly. This becomes particularly painful when you want to pass va_lists around to different functions. One handy feature of making your own version is that you can setup functions to log to wherever you like (the console, or different log files) - it all comes back to smart fprintf calls at the end of the day.
On the other hand if you just want to customise NSLog in-place, then really all you need to do is become familiar with a few handy compiler macros (such as __LINE__, __PRETTY_FUNCTION__, etc). This is the easier approach, and may be all that you're after, but it doesn't provide as much control as rolling your own.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With