1、nslog重定义
优点:可以自定义打印样式,真机测试,内容过长的时候不会被截断
缺点:打印速度比nslog慢
#define NSLog(FORMAT, ...) fprintf(stdout,"%s\n",[[NSString stringWithFormat:(@"@ > " FORMAT),[SLogManager currentDate] , ##__VA_ARGS__] UTF8String]);
2、重定义stringWithFormat:
+(void)LogWithFormat:(NSString *)format, ...
{
va_list ap;
va_start (ap, format);
NSString *body = [[NSString alloc] initWithFormat:format arguments:ap];
va_end (ap);
NSInteger length = body.length;
while (length > 1024) {
NSString *subString = [body substringToIndex:1024];
NSLog(@"\n%@", subString);
body = [body substringFromIndex:1024];
length = body.length;
}
NSLog(@"\n%@", body);
}
网友评论