2

I know that it's possible to do method swizzling for Selectors and Methods in Objective C. Is it possible to swizzle functions like NSLog to our custom function. I wanted to add some extra functionality along with NSLog in the custom function.

EDIT:

I finally ended up using another function which will call NSLog internally.

#define NSLog(...) CustomLogger(__VA_ARGS__);

void CustomLogger(NSString *format, ...) {
    va_list argumentList;
    va_start(argumentList, format); 
    NSMutableString * message = [[NSMutableString alloc] initWithFormat:format 
                                                arguments:argumentList];


    [message appendString:@"Our Logger!"];
    NSLogv(message, argumentList);

    va_end(argumentList);
    [message release];
}
Mahadevan Sreenivasan
  • 1,144
  • 1
  • 9
  • 26

1 Answers1

1

It seems possible, but entirely unsupported, and can change at any time.

See How do I redirect all errors, including uncaught exceptions, NSLog calls, and other logs, to a log file on Mac OS X?

Community
  • 1
  • 1
Arafangion
  • 11,517
  • 1
  • 40
  • 72