Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is my NSLog output?

I've just started out learning iOS development. I'm using some NSLog statements in my code but they don't appear to be output anywhere. My application is using the debug configuration and I'm running my application in the iPhone simulator from within Xcode. I've checked both the Xcode console (under the Run menu) and also Console.app on my Mac, but there's nothing.

What could be the problem?

like image 689
John Topley Avatar asked Mar 06 '11 22:03

John Topley


5 Answers

Make sure you have your Console activated. To do that, you can:

  • Go to View > Debug Area > Activate Console (From your Menu Bar)
  • Or press C on your keyboard
like image 200
Sheharyar Avatar answered Nov 14 '22 17:11

Sheharyar


NSLog() output on the simulator does indeed show up in the Console Mac OS X application.

Go to All Messages and then filter based on your app name to get rid of the fluff, and run again. You'll see it in your output if the NSLog code is actually being hit during the execution of your program.

like image 34
jer Avatar answered Nov 14 '22 17:11

jer


Use NSLog() like this:

NSLog(@"The code runs through here!");

Or like this - with placeholders:

float aFloat = 5.34245;
NSLog(@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat);

In NSLog() you can use it like + (id)stringWithFormat:(NSString *)format, ...

float aFloat = 5.34245;
NSString *aString = [NSString stringWithFormat:@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat];

You can add other placeholders, too:

float aFloat = 5.34245;
int aInteger = 3;
NSString *aString = @"A string";
NSLog(@"This is my float: %f \n\nAnd here is my integer: %i \n\nAnd finally my string: %@", aFloat, aInteger, aString);
like image 24
Fabio Poloni Avatar answered Nov 14 '22 15:11

Fabio Poloni


Moved from comment

Are you sure that line with NSLog is executed? Try to insert NSLog right after autorelease pool allocation in main.m

like image 41
hoha Avatar answered Nov 14 '22 15:11

hoha


Really weird. Just for the sake of experiment: try to redirect the NSLog output to some file like this:

freopen ("/out","w", stderr);
NSLog(@"1234567890");

If there is an output, then there is something wrong with your stderr.

like image 1
Max Avatar answered Nov 14 '22 16:11

Max