Why is my xcode 4.2 log always empty?

后端 未结 4 2033
深忆病人
深忆病人 2021-01-17 04:35

in a method that is accessed three times I want to write something to the log.

NSLog(@\"%@\", [response responseString]);

But there is noth

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-17 05:13

    When Console isn't behaving nicely for me (which happens sometimes when I'm doing driver level stuff or multi-threaded apps), a much more reliable thing to do is something like:

    - (void) printToLog: (NSString *) aFormattedStringToPrint
    {
        // don't forget to remove an older copy of this file before 
        // your app finishes launching
        FILE * aFile = fopen( "/tmp/debuggingoutput.txt", "a");
        if(aFile)
        {
             fprintf(aFile, "%s", [aFormattedStringToPrint UTF8String];
             fflush(aFile);
             fclose(aFile);
        }
    }
    

    (you can define a macro like LOGTHIS which might toggle between NSLog and the above more direct and to the point code)

    And then you can "tail -f /tmp/debuggingoutput.txt" in your Terminal window while debugging and if nothing appears there, then you know your debugging lines aren't getting hit.

提交回复
热议问题