The iOS framework that grows only as fast as its documentation
Debugging Tools

Macros

#define NIDPRINT(xx,...)   NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
 
#define NIDPRINTMETHODNAME()   NIDPRINT(@"%s", __PRETTY_FUNCTION__)
 
#define NIDCONDITIONLOG(condition, xx,...)
 
#define NIDERROR(xx,...)   NIDCONDITIONLOG((NILOGLEVEL_ERROR <= NIMaxLogLevel), xx, ##__VA_ARGS__)
 
#define NIDWARNING(xx,...)
 
#define NIDINFO(xx,...)   NIDCONDITIONLOG((NILOGLEVEL_INFO <= NIMaxLogLevel), xx, ##__VA_ARGS__)
 

Functions

int NIIsInDebugger (void)
 

Variables

NSInteger NIMaxLogLevel
 
BOOL NIDebugAssertionsShouldBreak
 

Overview

For inspecting code and writing to logs in debug builds.

Nearly all of the following macros will only do anything if the DEBUG macro is defined. The recommended way to enable the debug tools is to specify DEBUG in the "Preprocessor Macros" field in your application's Debug target settings. Be careful not to set this for your release or app store builds because this will enable code that may cause your app to be rejected.

Debug Assertions

Debug assertions are a lightweight "sanity check". They won't crash the app, nor will they be included in release builds. They will halt the app's execution when debugging so that you can inspect the values that caused the failure.

NIDASSERT(statement);

If statement is false, the statement will be written to the log and if a debugger is attached, the app will break on the assertion line.

Debug Logging

NIDPRINT(@"formatted log text %d", param1);

Print the given formatted text to the log.

Print the current method name to the log.

NIDCONDITIONLOG(statement, @"formatted log text %d", param1);

If statement is true, then the formatted text will be written to the log.

NIDINFO/NIDWARNING/NIDERROR(@"formatted log text %d", param1);

Will only write the formatted text to the log if NIMaxLogLevel is greater than the respective NID* method's log level. See below for log levels.

The default maximum log level is NILOGLEVEL_WARNING.

Turning up the log level while the app is running

NIMaxLogLevel is declared a non-const extern so that you can modify it at runtime. This can be helpful for turning logging on while the application is running.

NIMaxLogLevel = NILOGLEVEL_INFO;

Macro Definition Documentation

NIDPRINT   NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

Only writes to the log when DEBUG is defined.

#define NIDPRINT;
Discussion

This log method will always write to the log, regardless of log levels. It is used by all of the other logging methods in Nimbus' debugging library.

NIDPRINTMETHODNAME   NIDPRINT(@"%s", __PRETTY_FUNCTION__)

Write the containing method's name to the log using NIDPRINT.

#define NIDPRINTMETHODNAME;

NIDCONDITIONLOG

Value:
{ if ((condition)) { NIDPRINT(xx, ##__VA_ARGS__); } \
} ((void)0)
#define NIDPRINT(xx,...)
Only writes to the log when DEBUG is defined.

Only writes to the log if condition is satisified.

#define NIDCONDITIONLOG;
Discussion

This macro powers the level-based loggers. It can also be used for conditionally enabling families of logs.

NIDERROR   NIDCONDITIONLOG((NILOGLEVEL_ERROR <= NIMaxLogLevel), xx, ##__VA_ARGS__)

Only writes to the log if NIMaxLogLevel >= NILOGLEVEL_ERROR.

#define NIDERROR;

NIDWARNING

Value:
NIDCONDITIONLOG((NILOGLEVEL_WARNING <= NIMaxLogLevel), \
xx, ##__VA_ARGS__)
NSInteger NIMaxLogLevel
The maximum log level to output for Nimbus debug logs.
#define NIDCONDITIONLOG(condition, xx,...)
Only writes to the log if condition is satisified.

Only writes to the log if NIMaxLogLevel >= NILOGLEVEL_WARNING.

#define NIDWARNING;

NIDINFO   NIDCONDITIONLOG((NILOGLEVEL_INFO <= NIMaxLogLevel), xx, ##__VA_ARGS__)

Only writes to the log if NIMaxLogLevel >= NILOGLEVEL_INFO.

#define NIDINFO;

Function Documentation

NIIsInDebugger

Assertions that only fire when DEBUG is defined.

int NIIsInDebugger:;
Discussion

An assertion is like a programmatic breakpoint. Use it for sanity checks to save headache while writing your code.

Variable Documentation

NIMaxLogLevel

The maximum log level to output for Nimbus debug logs.

NSInteger NIMaxLogLevel;
Discussion

This value may be changed at run-time.

The default value is NILOGLEVEL_WARNING.

NIDebugAssertionsShouldBreak

Whether or not debug assertions should halt program execution like a breakpoint when they fail.

BOOL NIDebugAssertionsShouldBreak;
Discussion

An example of when this is used is in unit tests, when failure cases are tested that will fire debug assertions.

The default value is YES.