BetaDesigns( Blog ) Flex and Component Development

3Jul/100

Custom XCode Logger

I came across this method for creating a Debug Logger for XCode projects.
Basically you create a macro that says only process this piece of code if we are running in debug mode. This allows you to create logging throughout your application without having to worry about removing it before you do a release build as it won't be included in the release code.

To begin you need to add a GCC_PREPROCESSOR_DEFINITIONS | DEBUG=1 to your projects TARGET>Get Info>BUILD settings.

Next go into YOUR_APPLICATION_NAME_Prefix.pch file ( located under Other Sources ) and place the following macro.

 
#ifdef DEBUG
# define trace(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define trace(...)
#endif
 

This will create a custom Logger that can be used in the same way as NSLog except that it will output a more descriptive message showing the location and line number of where the log item is located.
edit: I have cheekily renamed it to trace();

 
trace( @" Does my debug tracer appear in production code?  %@",
@"NO!"  );
 
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.