I read this article: http://weakreference.wordpress.com/2011/06/22/overriding-nslog-on-ios/ .
The idea of โโthe article is to add these two things to the prefix.pch file of your application so that you can override the behavior of NSLog.
Two things I add:
#define NSLog(...) customLogger(__VA_ARGS__);
and
void customLogger(NSString *format, ...) { va_list argumentList; va_start(argumentList, format); NSMutableString * message = [[NSMutableString alloc] initWithFormat:format arguments:argumentList]; [message appendString:@"Our Logger!"];
xCode throws an o error matching error, which finds duplicates of customLogger.
Has anyone successfully redefined NSLog?
Thanks!
Edit in response to Rob:
Good Excellent. We are making progress! I moved things the same way you asked. Here is what we have now:
My user log:
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 in Thread 1.
source share