Skip to content

Instantly share code, notes, and snippets.

@moliyadi
Last active November 19, 2015 07:51
Show Gist options
  • Select an option

  • Save moliyadi/d949a705bf22e6e85c6c to your computer and use it in GitHub Desktop.

Select an option

Save moliyadi/d949a705bf22e6e85c6c to your computer and use it in GitHub Desktop.

Revisions

  1. moliyadi revised this gist Nov 19, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 将iOS的控制台输出存储到文件.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    Just add this block of code in applicationdidFinishLaunchingWithOptionslaunchOptions method in app delegate file, and it will create a log file in app Document Directory on iphone which logs all console log events. You need to import this file from itunes to see all console events.
    ```
    ```Objective-C
    if (!isatty(STDERR_FILENO)) {
    //判断控制台是否已连接,http://stackoverflow.com/questions/9619708/nslog-to-both-console-and-file
    //将控制台内容写入文件,http://stackoverflow.com/questions/2634929/objective-c-iphone-can-we-view-console-log-on-device
    @@ -12,5 +12,5 @@ if (!isatty(STDERR_FILENO)) {
    NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
    }
    }
    ```
  2. moliyadi revised this gist Nov 19, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 将iOS的控制台输出存储到文件.md
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,4 @@ if (!isatty(STDERR_FILENO)) {
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
    }
    ```
    ```
  3. moliyadi created this gist Nov 19, 2015.
    16 changes: 16 additions & 0 deletions 将iOS的控制台输出存储到文件.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    Just add this block of code in applicationdidFinishLaunchingWithOptionslaunchOptions method in app delegate file, and it will create a log file in app Document Directory on iphone which logs all console log events. You need to import this file from itunes to see all console events.
    ```
    if (!isatty(STDERR_FILENO)) {
    //判断控制台是否已连接,http://stackoverflow.com/questions/9619708/nslog-to-both-console-and-file
    //将控制台内容写入文件,http://stackoverflow.com/questions/2634929/objective-c-iphone-can-we-view-console-log-on-device
    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);
    }
    ```