I read this article: <a href="http://weakreference.wordpress.com/2011/06/22/overriding-nslog-on-ios/" rel="nofollow">http://weakreference.wordpress.com/2011/06/22/overriding-nslog-on-ios/</a>.
The idea of the article is to add these two things to the prefix.pch file of your app, so that you can override the behavior of NSLog.
The two things I'm adding are:
and
xCode throws an error match-o error, that it finds duplicates of customLogger.
Has anyone successfully overridden NSLog?
Thanks!
<strong>Edit in response to Rob:</strong>
Okay, great. We're making progress! I moved thing just like you asked. Here's what we have now:
My custom logger:
When I call +log, I get a SIBABRT error on Thread 1.
The idea of the article is to add these two things to the prefix.pch file of your app, so that you can override the behavior of NSLog.
The two things I'm adding are:
Code:
#define NSLog(...) customLogger(__VA_ARGS__);
and
Code:
void customLogger(NSString *format, ...) {
va_list argumentList;
va_start(argumentList, format);
NSMutableString * message = [[NSMutableString alloc] initWithFormat:format
arguments:argumentList];
[message appendString:@"Our Logger!"]; // Our custom Message!
NSLogv(message, argumentList); // Originally NSLog is a wrapper around NSLogv.
va_end(argumentList);
[message release];
}
xCode throws an error match-o error, that it finds duplicates of customLogger.
Has anyone successfully overridden NSLog?
Thanks!
<strong>Edit in response to Rob:</strong>
Okay, great. We're making progress! I moved thing just like you asked. Here's what we have now:
My custom logger:
Code:
void customLogger(NSString *format, ...) {
va_list args;
va_start(args, format);
va_end(args);
[newLogger log:format withArgs:args];
}
//This is a newLogger Method
+ (void) log:(NSString *)format withArgs:(va_list) args{
NSArray *occ = [format componentsSeparatedByString:@"%@"];
NSInteger characterCount = [occ count];
NSArray *stringItems = [format componentsSeparatedByString:@"%@"];
NSMutableString *tmp = [[NSMutableString alloc] initWithFormat: @"%@",[stringItems objectAtIndex:0]];
for( int i = 1; i < characterCount; i++ ) {
NSString *value = va_arg(args, NSString *);
[tmp appendString:value];
[tmp appendString:[stringItems objectAtIndex:i]];
}
// Need to alter the above and actually do something with the args!
[tmp appendString:@"\n"];
[[newLogger sharedInstance].logBuffer appendString:tmp];
if ([newLogger sharedInstance].textTarget){
[[newLogger sharedInstance].textTarget setText:sharedInstance.logBuffer];
}
}
When I call +log, I get a SIBABRT error on Thread 1.