Today we are introducing a new open source project: Cocoa Lumberjack
This is a revolutionary new logging framework for iPhone and Mac. Now you might be thinking "logging is boring".
But what if I told you that by using the framework you can actually make your application faster because it is an order of magnitude faster than NSLog?
What if I told you that the framework could allow you to debug your iPhone application remotely, by viewing its log statements in real time, via your web browser?
What if I told you it supports Grand Central Dispatch (if available).
I'm getting ahead of myself...
Let's start from the beginning.
Logging is one of those boring subjects for many developers. We all know we should be doing it. At a minimum we should be logging things like errors and warnings. Of course, when we're debugging we log all kinds of stuff. But what happens once the debugging is done?
Some languages have a plethora of powerful and mature logging frameworks. Take Java for example. But what about Cocoa? You don't often hear Mac/iPhone developers talk much about logging. Why is this?
Is it because Java and C# programmers are boring, and Cocoa developers are exciting?
No (but I'm sure many Cocoa programmers would like to think so). Every programmer wants to write good and stable code. Logging is one of the tools to help accomplish this task. So regardless of what the application does, a good logging framework can help.
So what do Cocoa programmers have available to them?
Log4Cocoa is one possible option. But it never really took hold for a number of reasons. It lacks obvious preprocessor options (many developers would like their log statements to be compiled out of their release builds). It appears to be slow (some say twice as slow as NSLog, and every log statement requires a dictionary lookup, even if the statement won't be executed). Development seems to have all but completely stopped several years ago. And the latest version doesn't contain a logger that can output to the Console application.
So most end up writing their own macros (kinda like this) that allows them to easily toggle log statements from their build. The good part is that it's really easy to use. The bad part is it still uses NSLog...
What's wrong with NSLog?
iPhone developers may be the most aware of NSLog's shortcomings. The iPhone keeps a very short history of log statements. This means that if your iPhone app misbehaves, you need to plug it into Xcode quickly, or any possible log statements may disappear.
And Mac developers know that their log statements are visible to any user via the Console application. If your application is too verbose, you'll hear about it from annoyed IT users.
It would be useful if you could send your log statements to a dedicated file. And while we're at it, how about we customize the format. Instead of just a prepended timestamp, what if we also included the file and method name and line number where the log statement came from. This is where a logging framework comes in...
The Lumberjack framework was designed to be fast, simple, powerful and flexible. As I mentioned earlier, it is faster than NSLog. In addition, the framework is simple to use, especially for those who are converting from NSLog. In fact, the default configuration behaves just like NSLog, so it's like a drop-in replacement.
We've taken considerable effort to document the project on the Cocoa Lumberjack Google Code project site.
There is a quick getting started page for those wondering what it would take to start using the framework in their application.
For those curious individuals, there is a performance page that provides benchmarks of the framework and details the underlying performance optimizations.
There is a page called Xcode Tricks that discusses how you can use different log levels for your debug and release builds. (There are even screenshots to guide you through the process.)
For advanced users who are already accustomed to logging frameworks, there is a page that shows how to customize the number and/or names of the various log levels. (So if you want 13 log levels, you can have them.) And there is also a page that shows how you can add fine grained logging.