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
15
votes
3 answers

Is there any danger in leaving NSLog statements when building an app for distribution?

For some reason, during my development cycle I find myself deleting NSLog statements that I had inserted to aid in debugging. I don't really know why I have this habit, I just do it. On occasion, during development I'll find that I'll run into a…
bpapa
  • 21,409
  • 25
  • 99
  • 147
15
votes
2 answers

Printing Instance ID to NSLog?

In the dealloc method for a class how would I print out the ID (or some other unique identifier) for the instance being deallocated? - (void)dealloc { NSLog(@"_deallocing: ??"); [super dealloc]; } Is this possible? I am just trying to get…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
15
votes
2 answers

Print NSMutableURLRequest Contents

I want to ask if anybody has ever tried printing out the values of a NSMutableURLRequest *request; Here's my scenario, I have formed my XML and tried sending it using Firefox Poster plugin, I am successful playing with valid and invalid contents, so…
mirageservo
  • 2,387
  • 4
  • 22
  • 31
14
votes
3 answers

Immediately flushing log statements using the Cocoa Lumberjack logging framework, the way NSLog flushes to console

Many iOS developers have found the Cocoa Lumberjack Logging framework to fill a need that simple NSLog statements don't. It's reminiscent of Log4J in the Java world. In any event, I have written my own custom formatter for Lumberjack, but what I…
idStar
  • 10,674
  • 9
  • 54
  • 57
14
votes
4 answers

Is there a way to capture the output of NSLog on an iPhone when not connected to a debugger?

I'm logging a bunch of data with NSLog(). Is there a way to capture the log data when my iPhone is not connected to my development machine and running under a debugger? For example, can I redirect it to a file and then read the log file back…
Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
14
votes
1 answer

Trying to NSLog an NSNumber ivar in an instance method

I'm working on a console app that is tracks different songs. I'm working on getting the song class up off the ground first and have run into a snag trying to log an nsnumber which has been allocated for the song duration into an nslog…
nickthedude
  • 4,925
  • 10
  • 36
  • 51
13
votes
3 answers

How can I control error level of NSLog messages on iOS?

I observed the NSLog() does log all my messages with error level Warning but when I look to the console I see other messages with different error levels like Info, or `Error. How can I control the error level of my messages?
sorin
  • 161,544
  • 178
  • 535
  • 806
13
votes
5 answers

Strange behaviour with NSLog

I'm using NSLog to inspect a UITextView. I have the following logging statements in my code: NSLog(@"textView: %@",textView); NSLog(@"textView.frame: %@",textView.frame); NSLog(@"[textView frame]: %@",[textView frame]); And in the…
Chris
  • 39,719
  • 45
  • 189
  • 235
13
votes
5 answers

How to disable NSLog all over the app?

I want to disable NSLog() across all instances in an app. I found some code that does that: #ifndef DEBUG #define NSLog // #endif But adding this code to each file isn't good idea. How can I make it easier?
Timur Bernikovich
  • 5,660
  • 4
  • 45
  • 58
12
votes
1 answer

Xcode 9, where are my NSLog()s going? Not showing in Xcode console or Console.app

I'm trying to do some basic logging while I work on an app. I tossed some NSLog()s into my code, but nothing is being printed to the Xcode console below. Literally nothing, not even some startup info as the app launches, etc. I've got my Xcode…
Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
12
votes
2 answers

How to display hexadecimal bytes using NSLog

How can I display the following bytes using NSLog? const void *devTokenBytes = [devToken bytes];
gabac
  • 2,062
  • 6
  • 21
  • 30
12
votes
1 answer

question concerning NSLog output %i, %d

I have question concerning a function I created. I would like to show the timeinterval in my console output. -(void)MyTimeInterval:(id)sender { NSDate *then = [NSDate date]; NSDate *now = [NSDate date]; NSTimeInterval interval = [now…
jovany
12
votes
7 answers

Logging the class name of all UIViewControllers in a project

We have received a HUGE project from outsourcing that we are trying to "repair". There are hundreds of view controllers within the project. Our goal is to easily determine which class we are currently looking at on the device. Our solution (which…
adamweeks
  • 1,332
  • 2
  • 14
  • 21
11
votes
1 answer

iOS / sqlite - How to print a prepared sqlite3_stmt to NSLog

I'm having some unexpected results with the data i'm inserting or replacing into my sqlite database. To trouble shoot the problem I'm trying to get a full print out of the prepared sqlite3_stmt (statement) in the below code. What I would like to…
KevinM
  • 1,799
  • 4
  • 28
  • 58
11
votes
5 answers

Should I remove NSLogs when releasing my App

Is it advisable to do any NSLogging in a shipping app? I know that I should not in heavily used loops. Or not log too verbosely. But I am not sure if it is a good practice to do so. Removing all the NSLogs prior to a release does not seem like a…
Besi
  • 22,579
  • 24
  • 131
  • 223