How do I disable NSLog?

I’d like to do the following in Xcode:

Find all NSLog commands without comments, and replace it with //NSLog…

In other words, I want to comment all NSLog calls. Is this possible? Is there an easy way to do this?

Do I need to disable NSLog before release Application?

When releasing an app for iPhone, if I disable NSLog(); will it perform better?

How do I flush NSLog’s buffer?

I have error handling code like this: if (ERROR) { NSLog(@<some message>); exit(-1); } The message logged with NSLog doesn’t always appear in the console, presumably because exit() terminates

How do I check NSLog output?

I would like to check if NSLog() for some string has actually printed out something. Is there a way I can check the length of the output of an NSLog statement or create a string from it? It’s for a p

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

How do I NSLog an NSDate?

With the code pasted below, I am trying to log an NSDate. What am I doing wrong here? NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@YYYY-MM-dd]; NSDate *toda

how do I get the day of the week using NSDate and show using NSLog in iOS? [duplicate]

Possible Duplicate: Objective C – How can i get the weekday from NSDate? How do I get the day of the week using NSDate and show using NSLog? I wonder the current day, such as today. Ex: NSLog(@the

Disable NSLog for a specific class

I know how you can disable all NSLog messages from answers like this one and this one. It’s yet unclear to me what should I define in my .pch file to conditionally disable NSLog in a separate class. A

How do I output a literal sequence with NSLog

I want NSLogto output a literal escape sequence, without treating it as a pattern. Take, for example NSLog(@image%03d.jpg);, who’s output I want to be the actual contents, image%03d.jpg instead of i

How do I totally disable caching in nHibernate?

How do I totally disable caching in nHibernate?

How to disable all the NSLog in Xcode 5 in iOS?

I have so many NSLog(@..); in xcode for print the value. So when i release the app i want to disable all NSLog in my Xcode instead of doing //NSLog. I have 2 questions. When i use Nslog That time i


There is a little hack that you could do. Search for all NSLog and replace them with //NSLog and than do another search for ////NSLog and replace them with //NSLog.

in the Menu bar : Edit > Find > Find and Replace in Workspace then, display options to use regular expressions. search/replace for “[^/]NSLog”

right click on NSLog statement in xcode and select “find in project” as would be prompted to a new window where you can follow the guidance given by Mihai Fratu.


You can do this in a single find and replace operation. You can just do this simple Regular Expression replace. This handles both the commented(//) and non-commented lines. This also works even if the previous commented lines has more than two forward slashes(like ///)instead of rwo. You can refer this link. Do the following steps.

  1. Select Edit > Find > Find and Replace in Workspace
  2. Style => Regular Expression
  3. Type (/)*(NSLog.*) in Find field.
  4. Do the find operation.
  5. Type ///2 in the Replace field.
  6. Do the replace operation.

Enjoy the beauty of regular expressions šŸ˜‰

The answers you have are correct for your question. But. Your real question is how to turn of NSLogs in certain conditions. i.e. you want them to show for Debug builds, and not for Release builds. In which case try defining and using the DLog() macro as described on Cocoa Is My Girlfriend. If you’re using Xcode4 it’s even easier because the Debug and Release builds define and undefine DEBUG so you don’t have to do that.

It’s a lot easier than commenting and uncommenting lines of code.

I have to do a separate answer because I cant comment yet, but one thing you really need to be careful about when you do a find and replace is something like this:

NSLog(@"blah blah");

[self doSomething];

If you comment out the nslog, the conditional gets associated with the method below it, correct me if I’m wrong

wait there is far more simple method. Just add the following lines when you dont need NSLOG to your constants file

#define NSLog                       //

and comment it when you need it.

EDIT: In latest Xcode, you get error on above statement. So I figured out the best way is

#define NSLog(...) 
#ifdef RELEASE
   #define NSLog(...) do { } while (0)

is the best way i found so far.

You can use following Preprocessor Directives, it will not go with release mode. So you don’t have to commenting NSLog().

#ifdef DEBUG

#define NSLog(…)

add this line into your .pch file

if you want log than comment it

#define NSLog if(1) NSLog

if you dont want log set 1 as 0.

How to disable NSLog in Xcode for Production stage

Add #define NSLog in appName-Prefix.pch file in Supporting Files Folder of your project and result file code look like…

// Prefix header for all source files of the 'NSLog' target in the 'NSLog' project

#import <Availability.h>

#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>

//Add this to disable NSLog
#define NSLog //

Add the following line to your .pch file

#define NSLog

for enable comment it

I would do this

#define EnableNSLog 1

#if EnableNSLog == 0
#define NSLog   //
#elif EnableNSLog == 1
#warning Disable NSLog

This should generate a warning message to remind me to disable NSLog before final release.

try this also:

    #define NSLog(@"YOUR MESSAGE HERE!") do { } while (0)