我已按照How to NSLog into a file创建自己的NSLog。
在iFob-Prefix.pch中: #import "Log.h"
#ifdef DEBUG_MODE
#define NSLog( args, ... ) _Log(@"Prefixs", __FILE__, __LINE__, __PRETTY_FUNCTION__, args);
#else
#define NSLog( args, ... )
Log.h中的
@interface Log : NSObject
void _Log(NSString *prefix, const char *file, int lineNumber, const char *funcName, NSString *format,...);
@end
Log.m中的
#import "Log.h"
#import <objc/runtime.h>
#define PADDING_TABS 10
@implementation Log
void _Log(NSString *prefix, const char *file, int lineNumber, const char *funcName, NSString *format,...) {
va_list ap;
va_start (ap, format);
format = [format stringByAppendingString:@"\n"];
NSString *msg = [[NSString alloc] initWithFormat:[NSString stringWithFormat:@"%@",format]
arguments:ap];
msg = formatJsonData(msg);
va_end (ap);
fprintf(stderr,"\n%s[%30s:%4d] - %s",[prefix UTF8String], [[[NSString stringWithUTF8String:file] lastPathComponent]UTF8String] , lineNumber, [msg UTF8String]);
append(msg);
}
每次通过[&lt;“object”&gt;时我都会收到错误说明]进入日志。 像:
NSManagedObjectContext *context = rasEngine.managedObjectContext ;
NSLog(@"context: %@",[context description])
错误:
答案 0 :(得分:1)
将NSLog( args, ... )
更改为NSLog( args... )
否则你在调用NSLog(@"content %@");
之类的东西而不传递对象