Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seeing the NSLog for an app running directly in simulator, not via Xcode

Is there any way I can see the console logs of an app running in the iOS simulator when I do not run the code via Xcode? I am directly opening the app from within the simulator. Can I see the NSLog statements printing somewhere?

like image 268
Abhinav Avatar asked Feb 17 '12 20:02

Abhinav


2 Answers

Yes. Here's a quote from Tools Workflow Guide for iOS:

When running your app in a simulator, you can access the app’s console logs in the Console app (located in /Applications/Utilities).

like image 61
picciano Avatar answered Nov 06 '22 04:11

picciano


From BYU CocoaHeads:

Redirected NSLog()

Occasionally, you may want to redirect your NSLog() output to a file so that you can examine it more conveniently. NSLog() works by outputting messages to STDERR, so all you need to do is redirect the STDERR stream to a file, and you're good to go. The following code will redirect it to a file on your desktop:

    int fd = creat("/Users/dave/Desktop/my_log",
                       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    close(STDERR_FILENO);
    dup(fd);
    close(fd);
    NSLog(@"this will be written to my_log");

This will only affect NSLog() calls from your application.

like image 25
beryllium Avatar answered Nov 06 '22 04:11

beryllium