Click here to support Nimbus development and make a donation at www.pledgie.com !
An iOS framework whose growth is bounded by O(documentation).
Debugging Tools

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;

Defines

#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

Define Documentation

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

Only writes to the log when DEBUG is defined.

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.

Definition at line 145 of file NIDebuggingTools.h.

#define NIDPRINTMETHODNAME ( )    NIDPRINT(@"%s", __PRETTY_FUNCTION__)

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

Definition at line 153 of file NIDebuggingTools.h.

#define NIDCONDITIONLOG (   condition,
  xx,
  ... 
)
Value:
{ if ((condition)) { NIDPRINT(xx, ##__VA_ARGS__); } \
} ((void)0)

Only writes to the log if condition is satisified.

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

Definition at line 162 of file NIDebuggingTools.h.

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

Only writes to the log if NIMaxLogLevel >= NILOGLEVEL_ERROR.

Definition at line 172 of file NIDebuggingTools.h.

#define NIDWARNING (   xx,
  ... 
)
Value:
NIDCONDITIONLOG((NILOGLEVEL_WARNING <= NIMaxLogLevel), \
xx, ##__VA_ARGS__)

Only writes to the log if NIMaxLogLevel >= NILOGLEVEL_WARNING.

Definition at line 177 of file NIDebuggingTools.h.

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

Only writes to the log if NIMaxLogLevel >= NILOGLEVEL_INFO.

Definition at line 183 of file NIDebuggingTools.h.


Function Documentation

int NIIsInDebugger ( void  )

Assertions that only fire when DEBUG is defined.

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

Definition at line 29 of file NIDebuggingTools.m.


Variable Documentation

NSInteger NIMaxLogLevel

The maximum log level to output for Nimbus debug logs.

This value may be changed at run-time.

The default value is NILOGLEVEL_WARNING.

Definition at line 20 of file NIDebuggingTools.m.

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

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.

Definition at line 21 of file NIDebuggingTools.m.

Generated for Nimbus by doxygen 1.7.4-20110629