Questions tagged [nslog]

Logs an error message to the Apple System Log facility.

The message consists of a timestamp and the process ID prefixed to the string you pass in. You compose this string with a format string and one or more arguments to be inserted into the string. The format specification allowed by this function is that which is understood by NSString’s formatting capabilities.

Displaying log messages in the system console while running your application is one of the oldest debugging mechanisms available. Using logging, you can generate a transcript describing the operations being performed by your application that you can review long after your application has finished running. Also, while your application is running, you can observe log messages being generated and written to the console as the events in your app they describe are taking place. As a developer, you are in complete control of the text and information displayed in the console by NSLog. Logging can reveal even the toughest to find problems in an app.

Here is an example of what a call to NSLog looks like:

NSString *message = @"test message";

NSLog( @"Here is a test message: '%@'", message );

Console:

Here is a test message: 'test message'

Reference:

Basic debugging with the NSLog function and the DEBUG preprocessor macro

667 questions
26
votes
2 answers

How to print a NSRange in NSLog

Say my range is created as NSRange myRange = {0,100}; How do I print myRange in NSLog? The following is not working NSLog(@"my range is %@",myRange);
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
25
votes
5 answers

Difference between NSLog and DLog

Can anyone tell me what the difference is between NSLog and DLog? I found about this DLog when I was looking over this project code: http://code.google.com/p/iphone-socks-proxy/
slonkar
  • 4,055
  • 8
  • 39
  • 63
25
votes
3 answers

How to print out string constant with NSLog on iOS

I have a string constant defined like this: #define kMyString @"This is my string text!"; Somewhere in the code I would like to print-out this piece of code with NSLog like that: NSLog(@"This is it: %@",kMyString); But get a build error: Expected…
Borut Tomazin
  • 8,041
  • 11
  • 78
  • 91
23
votes
5 answers

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…
John Topley
  • 113,588
  • 46
  • 195
  • 237
23
votes
7 answers

Logging a Swift enum using NSLog

I’m trying to log an enum: enum CKAccountStatus : Int { case CouldNotDetermine case Available case Restricted case NoAccount } NSLog("%i", CKAccountStatus.Available) The compiler complains: Type 'CKAccountStatus' does not conform…
zoul
  • 102,279
  • 44
  • 260
  • 354
22
votes
4 answers

Difference between NSLog and Printf statement for ObjectiveC

I want to know about the difference between the NSLog and the Printf statement in Objective-C (for application purpose...!) Why do all developer use NSLog instead of Printf ? Both look similar, but what is the difference in internal working? At…
Rushi3311
  • 253
  • 2
  • 4
  • 11
19
votes
2 answers

Xcode 8 Does not display the whole NSLog output

After upgrading to Xcode 8 GM today i noticed that NSLog isn't printing the whole log-message to the console. This is especially noticeable when working against an API that downloads a lot of information, like a REST API download all the products…
Pointblaster
  • 504
  • 3
  • 18
19
votes
4 answers

How to redirect the nslog output to file instead of console

I have cocoa application running on OS X. I have used NSLog for debugging purpose. Now I want to redirect the log statements to file instead of console. I have used this method but it results logging in Console as well as in file. -…
Unicorn
  • 2,382
  • 6
  • 29
  • 42
19
votes
2 answers

Objective C override %@ for custom objects

I'd like to override the default print function in NSLog for custom objects; For example: MyObject *myObject = [[MyObject alloc] init]; NSLog(@"This is my object: %@", myObjcet); Will print out: This is my object: Is there a…
Nick Cartwright
  • 8,334
  • 15
  • 45
  • 56
19
votes
5 answers

Is there a way to log all the property values of an Objective-C instance

I was just wondering if there is a quick and easy way of printing out to the log all of the various values of the properties to my class for debugging purposes. Like I would like to know what the values of all of the BOOLs, floats, etc. are.
daveMac
  • 3,041
  • 3
  • 34
  • 59
18
votes
4 answers

How to filter console output in Xcode

In my iOS project, I use one 3rd-party library, which is is incredible spamming into the console output. Can I apply any filtering to debug output.
ArtFeel
  • 11,701
  • 4
  • 29
  • 41
18
votes
4 answers

What are the numbers in the square brackets in NSLog() output?

What is the stuff between the [] in the log message below? I get this in my iPhone app, and I have no idea where the message is coming from. My first guess would be a line number, but which file would it be in? 2010-10-19 08:56:12.006…
Robbie
  • 831
  • 2
  • 14
  • 22
18
votes
5 answers

Logging to a file on the iPhone

What would be the best way to write log statements to a file or database in an iPhone application? Ideally, NSLog() output could be redirected to a file using freopen(), but I've seen several reports that it doesn't work. Does anyone have this…
Mike McMaster
  • 7,573
  • 8
  • 37
  • 42
16
votes
3 answers

Understanding NSLog syntax

(I'm a cocoa beginner and ) I'm wondering why we should do: NSLog(@"this is the variable value: %d",variable); and not something like this: [NSLog outputThis:@"this is the variable value: %d" param:variable];
tahir
  • 1,016
  • 1
  • 11
  • 21
15
votes
3 answers

how to create a breakpoint's log message action in xcode?

Been watching a WWDC video today about new features in xCode 4. They have mentioned that it a good idea to use log message actions on breakpoints along with "automatically continue after evaluation actions" enabled to output a variable's value for…
PrimeSeventyThree
  • 940
  • 2
  • 9
  • 24
1 2
3
44 45