自己改写了网络上面的nslog宏定义功能,感觉很好用,推荐给大家:
首先,在-Prefix.pch文件中加入如下代码:
#ifdef DEBUG # define mLOG(fmt, ...) do { \ NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \ NSLog((@"< FILE:%@; LINE:%d; FUNC:%s > --: " fmt), [file lastPathComponent], __LINE__, __func__, ##__VA_ARGS__); \ } while(0) #else # define mLOG(...) #endif
#ifdef DEBUG # define mLOG(fmt, ...) do { \ NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \ NSLog((@"< FILE:%@; LINE:%d; FUNC:%s > --: " fmt), [file lastPathComponent], __LINE__, __func__, ##__VA_ARGS__); \ [file release]; \ } while(0) #else # define mLOG(...) #endif
NSArray *arrtest = [[NSArray alloc] initWithObjects:@"one", @"tow", @"three", @"four", nil]; mLOG(@"%@", arrtest); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; mLOG(@"We all good friends.");
2014-05-15 12:20:14.063 ATMChaoRenJieKe1971[15222:60b] < FILE:NewsViewController.m; LINE:88; FUNC:-[NewsViewController viewDidLoad] > --: ( one, tow, three, four ) 2014-05-15 12:20:14.067 ATMChaoRenJieKe1971[15222:60b] < FILE:NewsViewController.m; LINE:93; FUNC:-[NewsViewController viewWillAppear:] > --: We all good friends.