[Tutorial] Debugging/Logging from apps on iPhone

Discussion in 'iOS Development' started by ipwnedmyphone, Feb 10, 2009.

  1. ipwnedmyphone

    ipwnedmyphone New Member

    Joined:
    Dec 3, 2008
    Messages:
    6
    Likes Received:
    0
    While searching for a way to find out what caused my application to crash, i came across this link. Using this, I can use printf statements to write into a log file on the phone, and find out exactly where the code fails.

    Lets assume that are application looks like this:

    SampleDB.app
    |
    |_ Info.plist
    |
    |_ Icon.png
    |
    |_ Default.png
    |
    |_SampleDB

    First Rename the SampleDB to something else:

    Code:
     mv SampleDB SampleDBMain
    Now create a new file, with the original app's name(SampleDB) and add the following code:
    Code:
     exec "$(dirname "$0")"/SampleDBMain &> /tmp/myapp.log
    Expect for the application name, everything should be same as provided.

    Place this file in the .app folder. Now your application should look like this:

    SampleDB.app
    |
    |_ Info.plist
    |
    |_ Icon.png
    |
    |_ Default.png
    |
    |_SampleDB ---> This is the shell script we created
    |
    |_SampleDBMain ---> This is the original file.

    Keep in mind that the ldid command should be run on the renamed file (SampleDBMain) and not the newly created shell script.

    After ldid, respring/reboot your device and launch your app from the springboard.

    After you are done or the application crashes, retrieve the log file myapp.log from /tmp directory on the phone.

    You can add printf() statements anywhere in your code, and they will appear in this log.

    This is great for logging messages for those who are not using XCode or are developing on Windows/Linux using the toolchain.

    Enjoy!!!
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    or...to make everything easier....

    check all your printf's and nslogs in syslog. =p
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    I hate the syslogd and the file it creates. I don't want to parse through every apps' output just to find my own. I just use GSLog to write to a file in tmp. Usually /tmp/MyApp.log. It makes life so much easier. You use GSLog exactly the same way as NSLog.


    EDIT: Also, any stdouts and stderrs, and other output (including crash reporting) will automatically wind up in the log file. Identically to how they would in the syslog.
  4. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    Any setup to be done to use GSLog? It sounds like a perfect thing to use for me.

    Please Register or Log in to view images

Share This Page