一种ios模拟器实时查看日志方法
2014-10-23 21:57
435 查看
下载本文pdf
我们在用xcode调试ios程序时通常会用NSLog来输出日志,默认是输出到xcode的debug控制台的,虽然我们可以通过字符串查找来看日志,但假如我们想通过过滤方式只查看特定的日志时,尤其时在实时输出的同时查看就很不方便了,在android的开发中可以通过TAG来输出,在windows我们可以通过wintail,在linux有tail下来查看,在mac当然也有tail和grep命令,那么我们是否可以利用这些工具呢?当然是可以的。将日志输出到文件,然后用tail, grep等命令对日志文件进行过滤查看
一,重定向输出日志
我们在AppDelegate添加调用这个方法
二,开始调试程序
我们先在xcode的output窗口看到我们日志的输出路径(这个路径只要模拟器不重启就不会改变):
三, 查看日志
打开命令行终端,我们先定位到这个目录:
通过tail命令实时查看日志
#tail -f console.log
也可以添加过滤条件
#tail -f console.log | grep -s "lbs"
你也可以开多个窗口通过不同的过滤条件来查看日志;
我们在用xcode调试ios程序时通常会用NSLog来输出日志,默认是输出到xcode的debug控制台的,虽然我们可以通过字符串查找来看日志,但假如我们想通过过滤方式只查看特定的日志时,尤其时在实时输出的同时查看就很不方便了,在android的开发中可以通过TAG来输出,在windows我们可以通过wintail,在linux有tail下来查看,在mac当然也有tail和grep命令,那么我们是否可以利用这些工具呢?当然是可以的。将日志输出到文件,然后用tail, grep等命令对日志文件进行过滤查看
一,重定向输出日志
- (void) redirectConsoleLogToDocumentFolder { #ifdef DEBUG //只在调试时使用,不然在真机下也会输出到沙盒目录 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; //首先输出日志文件的路径,方便我们定位目录 NSLog(@"log path:%@", documentsDirectory); //先删除上次输出的日志 NSString *logFile = [[NSString alloc] initWithFormat:@"%@/log.txt", documentsDirectory]; NSError *err; [[NSFileManager defaultManager] removeItemAtPath:logFile error:&err]; //重定向NSLog输出 NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"log.txt"]; freopen([logPath fileSystemRepresentation], "a+", stderr); #endif }
我们在AppDelegate添加调用这个方法
- (BOOL)application:(UIApplication *) applicationdidFinishLaunchingWithOptions:(NSDictionary *) launchOptions { [self redirectConsoleLog]; return YES; }
二,开始调试程序
我们先在xcode的output窗口看到我们日志的输出路径(这个路径只要模拟器不重启就不会改变):
三, 查看日志
打开命令行终端,我们先定位到这个目录:
通过tail命令实时查看日志
#tail -f console.log
也可以添加过滤条件
#tail -f console.log | grep -s "lbs"
你也可以开多个窗口通过不同的过滤条件来查看日志;
相关文章推荐
- iOS安全–实时查看模拟器的日志输出
- iOS安全–实时查看模拟器的日志输出
- Xcode模拟器和真机生成的日志查看(ios必知必会)
- Xcode模拟器和真机生成的日志查看(ios必知必会)
- iOS开发76-使用Xcode查看实时日志
- Xcode模拟器和真机生成的日志查看(ios必知必会)
- Xcode模拟器和真机生成的日志查看(ios必知必会)
- 查看tomcat线上部署项目实时日志的方法
- 一种基于实时日志的网站威胁检测的方法及系统
- iOS逆向 实时查看手机日志
- iOS实时查看App运行日志
- IOS端APP测试日志查看方法
- 实时查看日志文件更新的方法
- linux下实时查看tomcat运行日志的方法
- iOS设备模拟器文件查看方法
- iOS 生产环境之实时日志,都打包了怎么查看报错信息
- web在线实时聊天的一种方法
- 00027.Oracle查看alter日志的位置方法二
- 向ios模拟器里添加图片的简单方法
- Oracle11g日志查看方法