Adding LumberJack via source code to your project

ref – http://code.tutsplus.com/tutorials/cocoalumberjack-logging-on-steroids–mobile-15287

Go to CocoaLumberJack’s site and download their source code here

Unzip the LumberJack project and take a look at the LumberJack class folder’s source files.

lumberjack-class-directory

Import LumberJack’s Source files

Start a new xCode project.

Drag the listed files:

  • DDLog.h/.m
  • DDASLLogger.h/.m
  • DDTTYLogger.h/.m
  • DDFileLogger.h/.m
  • DDLegacyMacros.h
  • DDLegacyMacros.h

lumberjack-drag_to_proj

from the LumberJack project’s class folder, and into your project.

Creating the PCH file

Long ago, if there is a utility class that a developer needs for every of his source files, its very tiring for them to import that utility .h file in every of their source file. Hence, Prefix.pch was invented.

It is a precompiled header. It implicitly is included at the start of every source file. In other words, it’s like as if each source file adds:

Hence, you can easily include lumberjack’s functionality in all of your source code by using PCH file.

File >> New >> File
lumberjack-create-pch-file

Other >> PCH file

lumberjack-create-pch-file-2

use “Logging-PrefixHeader.pch”
make sure you check the checkbox for adding it to our target.

lumberjack-pch-file-3

Add

inside the ifndef statements.

Then at the end of the file, add

Your Logging-PrefixHeader.pch file should look like this:

Project Build Settings

Then in your Project, select your Target, Build Settings, and in the search box, type prefix. Scroll down and you’ll see Apple LLVM 7.0 – Language.

In Prefix Header, enter your .pch file name. In our case it would be Logging_PrefixHeader.pch.

Using the code

Add the following imports for DD in your AppDelegate.m file:

Then also in AppDelegate.m, insert the code as shown below:

Build and run the project. You should now see the log messages in your console.

Go to your Logging-PrefixHeader.pch file, highlight the macro LOG_LEVEL_VERBOSE, right click, and select “Jump To Definition”. Use all the different MACROS for setting what kind of log messages you want to see.

Installing xCode Colors Plugin

Install xCode color plugin by following the directions provided here.

Make sure you restart xCode.

Open up your project and in AppDelegate.m:

You should now see that your log messages are color-coded.