Posts Tagged ‘iOS’

Better Logging in iOS

I found this info in stackoverflow.com. The tip comes from Diederik Hoogenboom.

To better handle logging in your application you might want to use these macros:

#ifdef DEBUG

#   define DLog(fmt, …) NSLog((@“%s [Line %d] “ fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);


#   define DLog(…)


// ALog always displays output regardless of the DEBUG setting

#define ALog(fmt, …) NSLog((@“%s [Line %d] “ fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

I put these macros in a LOG.h file and add it to the .pch file located in the Other Sources folder in xCode, with an

#import “LOG.h”

To enable the DLog function just add the -DDEBUG flag in the “Other C Flags” option in your project’s configuration.

Just to remember you, the ALog will always print what you pass to it.

An example of a line from Dlog(@”Hello world”):

-[YourController yourMethod] [Line 100] Hello world


Read Full Post »