Created
July 26, 2012 09:31
-
-
Save tsbob/3181214 to your computer and use it in GitHub Desktop.
优化字符串定义的宏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define OC(str) [NSString stringWithCString:(str) encoding:NSUTF8StringEncoding] | |
#ifdef DEBUG | |
# define LOG(fmt, ...) do { \ | |
NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \ | |
NSLog((@"%@(%d) " fmt), [file lastPathComponent], __LINE__, ##__VA_ARGS__); \ | |
[file release]; \ | |
} while(0) | |
# define LOG_METHOD NSLog(@"%s", __func__) | |
# define LOG_CMETHOD NSLog(@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)) | |
# define COUNT(p) NSLog(@"%s(%d): count = %d\n", __func__, __LINE__, [p retainCount]); | |
# define LOG_TRACE(x) do {printf x; putchar('\n'); fflush(stdout);} while (0) | |
#else | |
# define LOG(...) | |
# define LOG_METHOD | |
# define LOG_CMETHOD | |
# define COUNT(p) | |
# define LOG_TRACE(x) | |
#endif | |
//真机调,保存在文件中 | |
- (void)redirectNSLogToDocumentFolder{ | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]]; | |
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName]; | |
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr); | |
} | |
- (void)applicationDidFinishLaunching:(UIApplication *)application { | |
// 真机测试时保存日志 | |
if ([CDeviceInfo getModelType] != SIMULATOR) { | |
[self redirectNSLogToDocumentFolder]; | |
} | |
..... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment