在iPhone上自定义NSLog功能 [英] Customizing NSLog Function on iPhone
本文介绍了在iPhone上自定义NSLog功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道可以对Objective C中的选择器和方法进行方法混淆.是否可以将诸如NSLog之类的函数混淆到我们的自定义函数中.我想在自定义函数中与NSLog一起添加一些额外的功能.
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.
我最终使用了另一个函数,该函数将在内部调用NSLog.
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];
}
推荐答案
似乎可行,但完全不受支持,并且可以随时更改.
It seems possible, but entirely unsupported, and can change at any time.
请参见如何操作我将所有错误(包括未捕获的异常,NSLog调用和其他日志)重定向到Mac OS X上的日志文件吗?
这篇关于在iPhone上自定义NSLog功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文