Re: When I don't want NSLog() for normal use?
Re: When I don't want NSLog() for normal use?
- Subject: Re: When I don't want NSLog() for normal use?
- From: Simon Stapleton <email@hidden>
- Date: Thu, 24 Oct 2002 10:50:17 +0200
I am using NSLog (and NSAssert for errors) for simple code tracing but
I obviously I don't want to log them for normal use, as it is waste of
CPU.
CPU nothing. Log space, yes...
So I have to do something like:
if(kTrace) NSLog(@"blabla...");
But to do this I need to declare a global header for kTrace and I feel
it's just so messy and awkward.
Is there an alternative way to do this? How do you implement debugging?
You've got a few choices here.
First one is to bracket all your calls to NSLog() with an #ifdef - for
example, you could use
#ifdef DEBUG
NSLog (...
#endif
and then make sure you have a -DDEBUG in your development build and not
your release build. This will give you a binary with no NSLogs built
in at all.
However, if you wanted to make it possible to turn-on-and-off debugging
on the fly (let's say you want to be able to get debug information in
the case of a customer bug report), a better option is this:
Use the stuff defined in <Foundation/NSDebug.h>, particularly
NSDebugEnabled. You then dont need to do anything except check the
global variable NSDebugEnabled in your NSLog wrapping, and turning
debug on is a simple matter of `defaults write myApp NSDebugEnabled
YES`. NSDebug.h is yor frend.
To save typing of course, in either case, there's no reason why you
shouldn't wrap NSLog with another C function or macro that does all the
checking for you.
Simon
--
PGP Key Id : 0x50D0698D
--
If the answer isn't obvious, the question is a distraction. Go find an
easier question.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.