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: Brian Redman <email@hidden>
- Date: Thu, 24 Oct 2002 02:26:43 -0400
Here's what I do to be able to control the verbosity in different
logical sections of my code.
It needs a header file and it ain't perfect for a couple reasons. Lets
see if the mailers send it through without munging it.
#define MG_DBG_GENERAL 0
#define MG_DBG_IMAP 1
#define MG_DBG_XTALK 2
#define MG_DBG_DOCK 3
#define MG_DBG_ACCOUNTS 4
#define MG_DBG_POP3 5
#define MG_DBG_SPOOL 6
#define MG_VLOG(level, logcall) { int mg_i,mg_d,mg_l; for (mg_i = 0;
mg_i < 8; mg_i++) { if ((mg_d=((debugLevel >> 3*mg_i)&7)) &&
(mg_l=(((level) >> 3*mg_i)&7)) && (mg_d >= mg_l)) { logcall; break; } }
}
#define MG_DBG_LEVEL(group, level) (level<<(group*3))
Declare a global debugLevel somewhere and set it with an environment
variable, argument or preference. Then you can spit out debugging at
different levels for different logic as such:
// level 1 general debugging
MG_VLOG(MG_DBG_LEVEL(MG_DBG_GENERAL, 1), NSLog(@"Debug level %d",
debugLevel));
// level 3 for the dock logic or 5 fpr the general logic
MG_VLOG(MG_DBG_LEVEL(MG_DBG_DOCK, 3)|MG_DBG_LEVEL(MG_DBG_GENERAL, 5),
NSLog(@"%@", flagString));
So for example debugLevel of 01042 will debug the dock logic at level
1, the imap logic at level 4 and the general logic at level 2.
07777777 will turn on everything everywhere. You could conditionally
redefine the macro to eliminate the debugging code all together.
ber
On Thursday, October 24, 2002, at 12:47 AM, Hisaoki Nishida wrote:
>
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.
>
>
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?
>
>
Thank you.
>
>
-Yuki
_______________________________________________
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.