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

3

12

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?

Circumvallate answered 17/2, 2012 at 20:15 Comment(1)
Organizer works for device & not for simulator.Circumvallate
C
2

I could manage to see the logs in "Console" application in MAC OS.

Circumvallate answered 17/2, 2012 at 22:1 Comment(0)
T
5

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).

Typehigh answered 17/2, 2012 at 20:33 Comment(0)
P
3

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.

Perpetuity answered 17/2, 2012 at 20:39 Comment(1)
Uhh, whoever wrote that article needs to work on their knowledge of POSIX; they are passively relying on the notion that the next open fd will be 2; this is not guaranteed to work and will actually do the wrong thing if another thread opens a file at the same time. The first close call and the dup should be replaced with dup2(fd, STDERR_FILENO).Tirado
C
2

I could manage to see the logs in "Console" application in MAC OS.

Circumvallate answered 17/2, 2012 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.