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

666 questions
447
votes
13 answers

How to print out the method name and line number and conditionally disable NSLog?

I'm doing a presentation on debugging in Xcode and would like to get more information on using NSLog efficiently. In particular, I have two questions: is there a way to easily NSLog the current method's name / line number? is there a way to…
rein
  • 31,307
  • 23
  • 77
  • 106
172
votes
6 answers

What is the Objective-C equivalent for "toString()", for use with NSLog?

Is there a method that I can override in my custom classes so that when NSLog(@"%@", myObject) is called, it will print the fields (or whatever I deem important) of my object? I guess I'm looking for the Objective-C equivalent of Java's…
George Armhold
  • 29,784
  • 45
  • 147
  • 224
156
votes
12 answers

Is it true that one should not use NSLog() on production code?

I was told this a few times in this very site, but I wanted to make sure this is really the case. I was expecting to be able to sprinkle NSLog function calls throughout my code, and that Xcode/gcc would automatically strip those calls out when…
jpm
  • 16,162
  • 33
  • 60
  • 66
134
votes
3 answers

NSLog/printf specifier for NSInteger?

A NSInteger is 32 bits on 32-bit platforms, and 64 bits on 64-bit platforms. Is there a NSLog specifier that always matches the size of NSInteger? Setup Xcode 3.2.5 llvm 1.6 compiler (this is important; gcc doesn't do…
Steven Fisher
  • 43,056
  • 20
  • 131
  • 184
120
votes
12 answers

Do I need to disable NSLog before release Application?

When releasing an app for iPhone, if I disable NSLog(); will it perform better?
RAGOpoR
  • 7,978
  • 18
  • 62
  • 97
118
votes
2 answers

NSLog an object's memory address in overridden description method

I am overriding an object's description method. I need to know how to print the object's memory address to replace {???} in the code below: -(NSString *) description { return [NSString stringWithFormat:@"\nparmeterOne:…
Undistraction
  • 38,727
  • 46
  • 165
  • 296
110
votes
11 answers

Warning: "format not a string literal and no format arguments"

Since upgrading to the latest Xcode 3.2.1 and Snow Leopard, I've been getting the warning "format not a string literal and no format arguments" from the following code: NSError *error = nil; if (![self.managedObjectContext save:&error]) { …
Alexi Groove
  • 6,526
  • 11
  • 43
  • 54
93
votes
6 answers

NSLog with CGPoint data

I have a CGPoint called point that is being assigned a touch: UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; I want to get the x coordinate value into my console log: NSLog(@"x: %s", point.x); When I use this,…
Spanky
  • 4,800
  • 6
  • 33
  • 35
89
votes
9 answers

iOS 10 doesn't print NSLogs

Nothing prints from NSLog on Xcode 8.0 beta (8S128d). printf is unchanged Here's my code: NSLog(@"hello from NSLog"); printf("hello from printf"); Here's the output on iOS 9 Simulator: 2016-06-17 09:49:10.887 calmapp-dev[28517:567025] hello from…
Tyler Sheaffer
  • 1,753
  • 1
  • 13
  • 16
63
votes
2 answers

How to use printf with NSString

I need to use something like NSLog but without the timestamp and newline character, so I'm using printf. How can I use this with NSString?
node ninja
  • 28,340
  • 55
  • 153
  • 242
59
votes
9 answers

iOS AutoLayout - get frame size width

I am developing using iOS 6 auto layout I would like to log a message displaying the frame width of the view. I can see the textView on the screen. But I get the width and height as zero, am I missing something ? NSLog(@"textView = %p",…
user1046037
  • 14,608
  • 12
  • 79
  • 117
57
votes
5 answers

Enable and Disable NSLog in DEBUG mode

I want to enable NSLog when I am in debug and disable it otherwise. A very simple thing is: #ifdef DEBUG NSLog(@"My log"); #endif But all this #ifdef and #endif is borring... :( So I try other thing: (.pch is good place to put it) #ifdef DEBUG # …
Rodrigo
  • 10,377
  • 18
  • 63
  • 95
55
votes
6 answers

How do I debug with NSLog(@"Inside of the iPhone Simulator")?

I'm used to programming and having log messages be viewable. I know you used to be able to use NSLog() to trace out messages when debugging Cocoa applications. What is the best way to "trace" messages when coding in an iPhone Xcode development…
Rob Sawyer
  • 1,973
  • 1
  • 23
  • 24
48
votes
4 answers

Any way to print in color with NSLog?

In a typical color terminal, there are escape sequences that one can use to print text in different colors. Typically there are 8 colors available. I tried using the standard, ANSI escape sequences for this in NSLog, but no dice. It does not support…
user945620
48
votes
7 answers

NSLog not printing to console

I have an Xcode project I've been working on for months. I've never had a problem with NSLog, but after upgrading to Xcode 4.2 nothing will log to the console. I even tried throwing this in viewDidLoad: - (void)viewDidLoad { [super…
Rob
  • 9,433
  • 12
  • 52
  • 87
1
2 3
44 45