How to Make the CocoaLumberjack work in your XCode project?

CocoaLumberjack is a good debugging tools that clearly define the log information output level so filtering the log information is possible to achieve. To use it should be very simple due to the Pods package manager tools. Here we introduce a way to let this good tool replace your old NSLog functions.

  1. Make a file named “Podfile” in the root directory of your project. Git it if you wish. Name need to be as indicated.
  2. Go to the directory in the terminal, call “pod install” to let the amazing pods handle the package installation.
  3.  From now on you should have another folder named “Pods” in your project which maintains the 3rd party library for you. For your git, remember to avoid version control on this directory since you have the Podfile so you can install them on other machines. This can avoid version control on the large package which is not necessary at all.
  4. Now it should be OK, but to use CocoaLumberjack, you need to import “CocoaLumberjack.h” in every file you want to have log, which is tedious. However, in XCode you can define a prefixed header which will be processed for the entire project.
  5. Go to the “Supporting Files” directory in your project’s left panel,  Add file there by clicking right mouth button. Choose others in the dialog and choose PCH file.
  6. Inside the created PCH file, added #import “CocoaLumberjack.h” there and it is done.
  7. You also need to make sure the compiler uses the PCH file. This can be done by going to Build Settings and search “Prefix Header”, go to the Language section and add Prefix Header to point to your file. Don’t forget to Enable Precompile Prefix Header also.

Now you should be able to log your project easier.