Re: Leave NSLog()s in Final Product? - solution
Re: Leave NSLog()s in Final Product? - solution
- Subject: Re: Leave NSLog()s in Final Product? - solution
- From: Jerry Krinock <email@hidden>
- Date: Tue, 16 Mar 2004 20:48:11 -0800
on 04/03/13 10:30, Chris Hanson at email@hidden wrote:
>
A better idea might be to switch to Bob Frank's Log4Cocoa framework
>
<http://log4cocoa.sourceforge.net/>
I looked at this and decided that I did not want to embed such a huge,
"full-featured" logger in my little application. So I wrote these two
functions to use instead of NSLog. They have a couple neat tricks in them,
so I thought I'd post them here.
The first one takes a C string, and the second takes an NSString, (for Obj-C
gurus who can't type a string constant any more without the "@" prefix).
void RLLog(int priority, const char * formatString, ...)
{
if (priority <= gLogging)
{
std::va_list argPtr ;
va_start( argPtr, formatString ) ;
NSLogv([NSString stringWithCString:formatString], argPtr) ;
}
}
void RLLog(int priority, NSString* formatString, ...)
{
if (priority <= gLogging)
{
std::va_list argPtr ;
va_start( argPtr, formatString ) ;
NSLogv(formatString, argPtr) ;
}
}
Now, you put these in some "utilities" file in your project, #import
"MyUtilities.h" in all your files, and then use an RLLog wherever you would
have used NSLog. They're pretty self-explanatory. You invoke them just
like NSLog except for the additional first argument, which is a the priority
level. gLogging is the global "logging level" variable, which I default to
0 for minimum logging, and otherwise set with a command-line argument when
launching the application, to get more logging when desired.
Finally, here is a pair of BBEdit 6.5 grep patterns which you can use for
changing all your NSLogs to RLLogs (with low priority = 5).
Search pattern:
([\t ]+?)NSLog\(@(.+?)\)[\s^\r]?;[\s^\r]+?
Replace pattern:
\1RLLog(5, \2) ;\r
_______________________________________________
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.