Logging Console for iOS

Peter FennemaiOSLeave a Comment

PFLoggingConsole is a development utility class that logs NSLog statements to the screen of a device. I find it very convenient for testing of communication between devices. I am using it while experimenting with the iOS Multipeer Connectivity framework. In this post I will explain what it does and how it works.

I have created a small project on Github that shows how to apply the PFLoggingConsole in a simple app (based on the Single View Application Template). You can download the sources associated with this post here.

When you run the app you will see the PFLoggingConsole screen:


The text on the console is produced by ordinary NSLog statements in the code.

Below is the PFLoggingConsole.h code:

PFLoggingConsole is a singleton UITextView subclass. By importing this PFLoggingConsole.h into another class file all NSLog calls of that class will log to this logging console. This works because the #define replaces all NSLog statements by calls to the PFLoggingConsole singleton.

The implementation code PFLoggingConsole.m:

So far the description of the PFLoggingConsole itself. The code snippet below is taken from the PFAppDelegate and shows the logic that presents the logging console to the user:

The method addLoggingConsole creates the PFLoggingConsole instance, adapts its size to the uiscreen size, and  adds it as a subview of the root viewcontroller view of the app.

To use the logging console in your own project add PFLoggingConsole.h and PFLoggingConsole.m to your source code tree, create an instance and add it as a subview wherever you want it to be in the view hierarchy. You can take the method addLoggingConsole shown above as an example.

Leave a Reply

Your email address will not be published.