iOS安全–实时查看模拟器的日志输出

最近在模拟器上面测试SDK,想看看模拟器断开xcode调试的日志输出,发现Xcode-Window-Devices里面并不能看到。

 

把日志重定向输出到log文件,便可以看到实时的log日志。

 

重定向日志输出代码:

1
2
3
4
5
6
7
8
9
10
- ( void )redirectConsoleLog {
#ifdef DEBUG
    NSString  *documentDir  = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory , NSUserDomainMask , YES ) [ 0 ] ;
    NSLog (@ "documentPath : %@" ,documentDir ) ;
    
     //重定向NSLog
    NSString * logPath  =  [documentDir stringByAppendingPathComponent :@ "console.log" ] ;
     freopen ( [logPath fileSystemRepresentation ] ,  "a+" , stderr ) ;
#endif
}

 

然后在AppDelegate里面添加这个方法。

1
2
3
4
-  (BOOL )application : (UIApplication  * )application didFinishLaunchingWithOptions : (NSDictionary  * )launchOptions  {
    
     [self redirectConsoleLog ] ;
}

 

运行Xcode,得到document的目录,然后定位到该目录下面。

1
2
3
documentPath  :  /Users /Monkey /Library /Developer /CoreSimulator /Devices /EC652E7F -BEAD - 4153 -9F56 -7DC025D4050C /data /Containers /Data /Application /3741A5B7 -DF67 - 4872 -B0F2 -4E6125C27E82 /Documents

cd   /Users /Monkey /Library /Developer /CoreSimulator /Devices /EC652E7F -BEAD - 4153 -9F56 -7DC025D4050C /data /Containers /Data /Application /3741A5B7 -DF67 - 4872 -B0F2 -4E6125C27E82 /Documents

 

使用tail –f console.log实时查看。也可以使用tail –f console.log | grep “xxx”,进行过滤。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd   /Users /Monkey /Library /Developer /CoreSimulator /Devices /EC652E7F -BEAD - 4153 -9F56 -7DC025D4050C /data /Containers /Data /Application /3741A5B7 -DF67 - 4872 -B0F2 -4E6125C27E82 /Documents
tail  -f console. log

2016 - 03 - 11  11 : 20 : 43.430 BugrptSDKDemo [ 33376 : 6921912 ]  <WORKFLOW >: sdk catch a exception
2016 - 03 - 11  11 : 20 : 43.922 BugrptSDKDemo [ 33376 : 6921912 ]  <Info > Bugrpt : catch a fatal signal : 6  [ 6 , 0 , 0 ]
2016 - 03 - 11  11 : 20 : 43.922 BugrptSDKDemo [ 33376 : 6921912 ]  <Debug > Bugrpt : crash count is :  1
2016 - 03 - 11  11 : 20 : 43.922 BugrptSDKDemo [ 33376 : 6921912 ]  <Debug > Bugrpt : CrashData is sessionEvent : (
     "sdk[1.1.2] handle signal:6 info(6,0,0)"
)
             crashTime : 1457666443431
             handler :Signal Handler
             type :NSRangeException (SIGABRT )
             error :***  - [__NSArrayI objectAtIndex : ] : index  3 beyond bounds  [ 0 ..  2 ]
             address : 0x108e1a0ae
             crashThread : 1803
             lastExceptionInfo :
             name : ( null )             arch : ( null )             uuid : ( null )             addr : ( null )
             bininfos : ( null )
             crashStackNames : ( null )

Log打印:
NSLog(@”this is my log”);
fprintf(stderr,”%s\n”,”this is my log”);

本文链接:http://www.blogfshare.com/redirect-console-log.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值