#ifdef DEBUG
# define YXCLog(fmt, ...) NSLog((@"%@ ""%@ " "%d : " fmt), NSStringFromClass([self class]), NSStringFromSelector(_cmd), __LINE__, ##__VA_ARGS__);
#else
# define YXCLog(...);
#endif
写入代码测试
@implementation YXCPerson
- (instancetype)init {
if (self = [super init]) {
YXCLog(@"初始化");
[self test];
}
return self;
}
- (void)test {
int a = 10;
YXCLog(@"%d", a)
}
@end
输出格式
YXCPerson init 22 : 初始化
YXCPerson test 32 : 10
其他格式
#define kYXCDateString ({\
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; \
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss.SSS"]; \
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; \
dateString; \
})
#define kYXCClass [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent
#ifdef DEBUG
#define YXCLog(fmt, ...) NSLog((@"%s " "%d行 : " fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__);
#define YXCPrintf(...) printf("%s : %s %s %d行 : %s\n", [kYXCDateString UTF8String], [kYXCClass UTF8String], __FUNCTION__, __LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]);
#else
#define YXCLog(...);
#define YXCPrintf(...);
#endif
网友评论