Customizing NSLog Function on iPhone

[亡魂溺海] 提交于 2019-12-11 02:10:36

问题


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];
}

回答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?



来源:https://stackoverflow.com/questions/4553017/customizing-nslog-function-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!